在下面的Java代碼:爲什麼這個for-loop被跳過?
public static void main(String[] args) {
Integer[] k = new Integer[] {0, 1, 2, 3};
int m = 0;
while (m < k.length) {
for (int i = 0; i < k.length && k[i] != null; i++)
System.out.print(k[i] + " ");
System.out.println("");
k[m++] = null;
}
}
我試圖讓下面的輸出:
0 1 2 3
1 2 3
2 3
3
然而,內部的for循環的第一遍後一起跳過,也就是說,後0 1 2 3的輸出,這是因爲第一個元素在第一次傳遞後被設置爲null,但我不明白爲什麼這很重要,有人能解釋一下嗎?真的很困惑。提前致謝。 :)
你知道什麼'K [i] = null'在環測試手段!? – user2357112
And ...你知道'k [m ++] = null'是什麼嗎? –
我強烈建議學習使用您的調試器。 –