這段代碼(Java)不起作用,我找不出原因。Java for while while循環無法按預期工作
int[][] arr = {{0, 0, 0}, {0, 1, 0}, {0, 0, 0}};
for(int a = 0; a < arr.length; a++) {
for(int b = 0; b < arr[a].length;) {
int c = 1;
if (arr[a][b] == 0) {
while((arr[a][(b+c)] == 0) && ((b+c)!=(arr[a].length-1))) {
c++;
}
addBar(b, a, c); // Use these values in another function...
b = b + c;
} else {
b++;
}
}
}
問題:b < arr[a].length;
沒有得到尊重和再次循環。我究竟做錯了什麼?
而在循環 – Pierre
循環使用調試,看看會發生什麼。 –