
vtuqpfiy
这里好冷清。。发个JAVA经典报数问题数组方法解答
>>
完整版
学校老师给出的题。。我想了好久才想出来 问题是这样的 : 有100个人报数。。每逢7的倍数就出列。。直到队列里剩下50个人为止,问哪些人出列了?
public class baoshu {
public static void main(String[] args) {
boolean[] bairen = new boolean[100];
int next = 1;
int index = 0;
int shengyu = 100;
while (shengyu > 50) {
if (bairen[index] == false) {
if (next == 7) {
bairen[index] = true;
--shengyu;
next = 1;
System.out.println((index + 1));
} else {
next++;
}
}
index++;
if (index == 100) {
index = 0;
}
}
}
}
ingramli
xiaowuhello
xiaowuhello
vtuqpfiy
xiaowuhello
vtuqpfiy
邵丑旦
直接用来记录所报的数就好了嘛
展开Biu
~84~ next直接用来记录所报的数就好了嘛。像这样:
if (bairen[index] == false) {
if (next%7==0) {
bairen[index] = true;
--shengyu;
System.out.println((index + 1));
}
next++;
有错轻拍 ~XD
[查看全文]
xiaowuhello