今天在閱讀拳擊和自動裝箱時,我想出了一個場景,並發現奇怪的行爲,我被困在無限的循環中。for循環在java中的奇怪行爲
我檢查了我的代碼兩次,但我沒有發現任何錯誤。 如果任何人可以看看,並建議我在哪裏做錯了,所以我會出來這個無限循環
請找到下面的代碼。
public class InTheLoop {
public static final int END = Integer.MAX_VALUE;
public static final int START = END - 100;
public static void main(String[] args) {
int count = 0;
//Infinite loop starts.
for (int i = START; i <= END; i++) {
count++;
System.out.println(count);
}
// This never got printed.
System.out.println("hi I am out of for loop" +count);
}
}
你可能已經在循環中打印了我的值,並且輸出對你來說是自我解釋的。 :) –