-5
有人可以解釋這個代碼背後的思考過程嗎?我對它的工作原理感到困惑。這是該代碼是解決這樣的問題:這個代碼如何填充10個不同的隨機數字的數組?
寫代碼(使用一個或多個環)來填充的陣列的「a」與圖1和10
之間謝謝10張不同的隨機數這麼多的任何幫助!
public static void main(String[] args){
//R8.8
int a[] = new int[10];
Random randomGenerator = new Random();
for (int i = 0; i < a.length; i++){
a[i] = 1 + randomGenerator.nextInt(100);
}
for (int i = 0; i < a.length; i++) {
int number = 1 + randomGenerator.nextInt(100);
int count = 0;
for (int j = 0; j < i; j++) {
if (a[j] == number) {
count += 1;
}
}
if (count > 0) i -= 1;
else a[i] = number;
}
}
}
[您是否嘗試過使用調試器進行調試?](https://en.wikipedia.org/wiki/Debugger) – robotlos