I have a sample code which creates an \"array\" of size 10 and tries to initialize it with reverse values in a For loop e.g:(9,8,7,6,5...0):
int[] array = ne
You are already getting the values out of the array
with your foreach loop, which you are using as an index again into the array, yielding the values in order again.
Just print k
. Change
for (int k : array) {
System.out.println(array[k]);
}
to
for (int k : array) {
System.out.println(k);
}
End of the output:
9
8
7
6
5
4
3
2
1
0