我有这样的代码,我试图打印以下形状了......倒车的Java For循环
****
* *
**
*
目前代码:
System.out.print("\nEnter number of rows: ");
rows = kybd.nextInt();
for (int i = 0; i < rows; i++) {
System.out.print("*");
}
for (int i = 0; i < rows; i++) {
for (int j = 1; j <= i; j++) {
if (j == 1 || j == rows - 1 || j == i) {
System.out.print("*");
} else {
System.out.print("0");
}
}
System.out.println();
}
出于某种原因,它打印出像这个:
****
*
**
* *
任何想法如何扭转第二个循环,所以它打印另一种方式?
_For某种原因_...你要我们找到原因,因为你不知道如何调试? –
'System.out.print(“0”)如何进入? – NPE
你想'for(int i = rows - 1; i> 0; i - )'。你想在你进一步深入之前去阅读所有关于'for'循环的内容。 –