0
Would you tell me why this output is 2? Why not 0?
int[] a = {100, 89, 6,3}; for (int I = 1; I < a.length; I++){ a[I] = a[I - 1] %a[I]; } System.out.println(a[i]); }
2 Answers
+ 1
The loop starts at 89 (index 1):
Element 0 is unaffected
Element 1 = 100 % 89 = 11
Element 2 = 11 % 6 = 5
Element 3 = 5 % 3 = 2
Now i equals 4, the loop stops, and the last value is printed, which is 2.
+ 1
ooo, I got it, thank you Naitomea