我的程序不會停止運行,我不確定我做錯了什麼。預先感謝任何幫助!在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