The following code is supposed to sort the array initialized below.
int[] intArray = { 32, 42, 1, 23, 56, 75, 32, 23 };
int temp = 0;
for (int i = 0; i < intArray.length; i++) {
for (int j = 1; j < intArray.length; j++) {
if (intArray[j - 1] > intArray[j]) {
temp = intArray[j - 1];
intArray[j - 1] = intArray[j];
intArray[j] = temp;
}
}
}
What should you type to get the sorted array and where should you type it?
I have tried some options such as System.out.println(temp)
between the last two closing brackets and the one before those, but I am not getting all the values printed, and 32
is printing many times instead.
Writing the code System.out.println(j)
or System.out.println(i)
in the same area doesn't work either. Can you explain why these codes don't work?