I have this piece of code:
int[] tab2 = {1, 2, 3, 4, 5, 6 ,7, 8, 9, 0};
for(int i : tab2)
System.out.print(i + " ");
int[] tab3 = {1, 2, 3, 4, 5, 6 ,7, 8, 9, 0};
for(int i : tab3)
System.out.print(tab3[i] + " ");
The first loop gives me 1 2 3 4 5 6 7 8 9 0
while the second one gives me 2 3 4 5 6 7 8 9 0 1
how come? Isn’t the first index of an array 0?
In the second loop you are printing value by looking from tab3’s items.