我在试图弄清楚如何使用扫描仪创建具有三个嵌套 for 循环的金字塔时遇到了麻烦。
我必须做到这一点
Enter a number
6
1 2 3 4 5 6
- 1 2 3 4 5
- - 1 2 3 4
- - - 1 2 3
- - - - 1 2
- - - - - 1
我基本上已经尝试过了,我知道这是错误的,但我知道我必须做什么,但我不知道该怎么写。
Scanner ent= new Scanner(System.in);
System.out.println("Enter a number");
int x= ent.nextInt();
for(int a = x; a >= 1; a--) {
for(int c=1;c<=x;c++) {
System.out.print("_");
for(int b = 1; b <= a; b++) {
System.out.print(d + " ");
}
}
System.out.println("");
}
烙印99
慕少森
相关分类