我的程序不会停止运行,我不确定我做错了什么。预先感谢任何帮助!在java中修复无限循环
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ArrayList<NumberOperations> numOpsList = new ArrayList<NumberOperations>();
System.out.println("Enter a list of positive integers separated "
+ "with a space followed by 0:");
int x = in.nextInt();
NumberOperations newNumOp = null;
while (x != 0) {
newNumOp = new NumberOperations(x);
numOpsList.add(newNumOp);
int index = 0;
while (index < numOpsList.size()) {
NumberOperations num = numOpsList.get(index);
System.out.println("For: " + num);
// add print statement for odds under num
System.out.println("\tOdds Under: " + newNumOp.oddsUnder());
// add print statement for powers of 2 under num
System.out.println("\tPowers of 2 under: " + newNumOp.powersTwoUnder());
index++;
}
}
}
您可以从修改'x'开始。 – 2014-09-29 00:28:23
解释你的程序做什么以及预期的结果是什么? – 2014-09-29 00:29:24
你为什么期望它停止? – SLaks 2014-09-29 00:30:38