【发布时间】:2023-03-23 16:03:02
【问题描述】:
class things {
public static void main(String args[]) {
int [][] nothing;
nothing = new int [4][5];
int i,j,k = 0;
for(i=0;i<4;i++)
for(j=0;j<5;j++) {
nothing[i][j] = k;
k++;
}
// Display the 2-D array
for(i=0;i<4;i++) {
for(j=0;j<5;j++)
System.out.print(nothing[i][j] + " ");
System.out.println();
}
}
}
在给定的代码中,{ 在第一个循环集的第二个嵌套 for 循环中,但 { 在第二个循环集的循环的第一行。 那么为什么以及何时在 Java 的循环中使用 {}。我的意思是当 {} 被移除时,我会得到完全不同的输出。
【问题讨论】: