【发布时间】:2019-10-15 03:26:36
【问题描述】:
编写一个程序,对介于两者之间的任何给定整数生成以下输出 包括 1 和 9。
输入一个整数值[1..9]:6
1
12
123
1234
12345
123456
666666
66666
6666
666
66
6
我已经完成了上半部分,但我无法通过重复的用户输入找出底部。
package lab7;
import java.util.Scanner;
public class problem5 {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
System.out.println("Input an integer between 1 and 9");
int input = scan.nextInt();
while (input <= 9) {
for (int i = 1; i <= input; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j);
}
System.out.println();
}
break;
}
}
}
预期结果:包含在顶部;到目前为止的实际结果(输入 5):
1
12
123
1234
12345
【问题讨论】:
-
当您达到所选数字时,您需要记住金字塔的深度。然后你做一个新的循环来减少这个深度
-
:s/deep/depth/g
标签: java