数字金字塔
作者:互联网
数字金字塔
import java.util.*;
class Main {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter the lines: ");
int lines = input.nextInt();
if(lines >= 1 && lines <=15){
for(int i = 1; i <= lines; i++){
for(int j = lines; j >= i; j--)//输出左边
System.out.print(" ");
for(int j = 0; j < i-1 ; j++) //输出中间i j:0到(i-2) i-j:i到2
System.out.printf("%2d",i-j);
for(int j = i-1; j >= 0; j--)//输出右边i j:(i-1)到0 i-j:1到i
System.out.printf("%2d",i-j);
System.out.print("\n");
}
}
}
}
四种图案
标签:数字,int,lines,System,printf,print,金字塔,out 来源: https://www.cnblogs.com/doudou-20123/p/16308917.html