[英]while until condition doesn´t work
i want to write a little program, but don´t know why my loop isn´t working correctly.我想写一个小程序,但不知道为什么我的循环不能正常工作。
while ((!ss.legal(myNumbers, colRand, rowRand, numRand)) || (triedNumbers.size() != 9)) {
System.out.println(triedNumbers.size());
// if(triedNumbers.size()==9) break;
numRand = getRandomNumber(1,9);
if (!triedNumbers.contains(Integer.valueOf(numRand))) {
triedNumbers.add(Integer.valueOf(numRand));
}
}
The thing is the second condition.事情是第二个条件。 My syso-command tells me the size is already 9 but the loop doesn´t end?
我的 syso 命令告诉我大小已经是 9 但循环没有结束?
If the random number is fine the legal method returns true
.如果随机数正常,则合法方法返回
true
。 So the loop should end.所以循环应该结束。 If the size of the map gets 9, it should also end the loop because I am only checking the numbers from 1 to 9.
如果地图的大小为 9,它也应该结束循环,因为我只检查从 1 到 9 的数字。
Replace ||
替换
||
(or) with &&
(and). (或)与
&&
(和)。 As it is even if the size is already 9 the loop will still continue as long as the first condition is true即使大小已经是 9,只要第一个条件为真,循环仍然会继续
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.