【发布时间】:2014-02-13 05:03:52
【问题描述】:
我是 Java 新手,我正在尝试理解嵌套的 while 循环。我正在尝试编写一个程序来打印以下输出:
999999999 on the top line,
88888888 on the next,
7777777 etc,
666666 etc,
55555
4444
333
22
1
我很容易使用 for 循环来做到这一点,但现在我想用 While 循环来做同样的事情。问题是我的代码在当前状态下只打印第一行九,然后看起来内部的 While 循环不再运行了。
我非常困惑,我认为我的任何标准都不是重言式,但我不太了解重言式。请解释我的循环逻辑有什么问题。循环对我来说仍然是一种神秘的巫术。
int outer = 9;
int inner = 1;
while (outer >= 1)
{
while(inner <= outer)
{
System.out.print(outer);
inner++;
}
System.out.println();
outer--;
}
【问题讨论】:
标签: java while-loop nested-loops