0
我想知道爲什麼for循環通過參數計數三次並且在第一次循環之後不停止?這是我的代碼:for循環爲什麼要經過三次參數?
public class test2 {
public static void main(String[] args) {
int N = args.length;
int[] x = new int[N];
int count = 0;
for (int i = 0; i < x.length; i++) {
x[i] = Integer.parseInt(args[i]);
}
for (int i = 0; i < N; i++) {
for (int j = i+1; j < N; j++) {
if (x[j] != x[j-1]) {
count++;
}
System.out.println(count);
}
}
System.out.println(N-count);
}
}
爲什麼你認爲之後應該停止第一個循環? –
因爲你有3個for循環? –
我的意思是在它將所有數字N,N假設爲正整數f.x. {1,1,1,3,4,5,5,6}中的整數後停止。這是假設打印出2,因爲有兩個數字出現不止一次是{1,5} –