为什么我的while(left > 1) 一直报错??
本帖最后由 yangkaiyun 于 2012-10-27 17:13:50 编辑
public static void main(String[] args) {
boolean[] a = new boolean[10];
for(int i = 0;i < a.length;i++) {
a[i] = true;
}
}
int left = a.length;
int counts = 0;
int index = 0;
while(left > 1) {
if(a[index] == true) {
counts++;
if(counts == 3) {
counts = 0;
a[index] = false;
left--;
}
}
index++;
if(index == a.length) {
index = 0;
}
}
……
[最优解释]
你的括号,不对称哟~少了好几对。
public class Derf {
public static void main(String[] args) {
boolean[] a = new boolean[10];
for(int i = 0;i < a.length;i++) {
a[i] = true;
}
int left = a.length;
int counts = 0;
int index = 0;
while(left > 1) {
if(a[index] == true) {
counts++;
if(counts == 3) {
counts = 0;
a[index] = false;
counts--;
}
}
index++;
if(index == a.length) {
index = 0;
}
}
}
}
a[i] = true;
}
int left = a.length;
int counts = 0;
int index = 0;
while(left > 1) {
if(a[index] == true) {
counts++;
if(counts == 3) {
counts = 0;
a[index] = false;
left--;
}
}
index++;
if(index == a.length) {
index = 0;
}
}
}
}
[其他解释]
不是那样的,我的错误提示是while。。郁闷啊、
[其他解释]
counts到3,a[index] = false变成FAlse不是死循环了么- -!
[其他解释]
谢谢大家,我终于发现了,很低级的错误,是while放在了main函数外边了。。。所以while出错了、