public class HelloWorld { public static void main(String[] args) { System.out.println("打印直角三角形"); for (int i = 1; i<=3;i++ ) { System.out.print("*"); } System.out.println(); } } } 把j++改为i++后*无限循环打印,I到3不是会直接跳出循环吗,求解释
哦哦。谢谢
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i; i++) {
System.out.print("*");
}
System.out.println();
}
这样写的话j一直等于1,一直小于i,所以一直在循环
for (int j = 1; j <= i; i++) {
System.out.print("*");
}