Why is this code "bad"? In all of the selection sort codes I am learning from, they do it much differently. I will learn the proper code from the book, but I would love to know why this particular code is bad.
public class Main {
public static void main(String[] args) {
int[] array = {8, 3, 5, 7, 9, 2, 4, 6, 8, 0};
System.out.println("The sorted array is: ");
displayArray(selectionSort(array));
}
public static int[] selectionSort(int[] list) {
int[] result = list;
for (int i = 0; i < result.length - 1; i++) {
for (int j = i + 1; j < result.length; j++) {
if (result[i] > result[j]) {
int temp = result[i];
result[i] = result[j];
result[j] = temp;
}
}
}
return result;
}
public static void displayArray(int[] list) {
for (int i = 0; i < list.length; i++) {
if ((i + 1) % 5 == 0)
System.out.println(list[i]);
else
System.out.print(list[i] + " ");
}
}
}