import java.util.*;
public class Sort {
public static void main(String[] args) {
//driver method
int[] array = new int[10];
System.out.println("Please enter ten integers");
insertionSort(array);
}
public static void insertionSort(int[] array) {
Scanner kybd = new Scanner(System.in);
int min, temp, n = array.length;
for (int i = 0; i < n; i++) {
array[i] = kybd.nextInt();
}
for (int pass = 0; pass < n; pass++) {
for (int i = 1; i < n; i++) {
min = pass; // initialise subscript min
if (array[i] < array[min]) {
min = i; // min so far
temp = array[pass]; // swap a[pass] & a[min]
array[pass] = array[min];
array[min] = temp;
} // end of each pass
}
for (int j = 0; j < n; j++) {
System.out.print(array[j] + " ");
}
System.out.print("\n");
}
}
}
Hey, having a real problem with this code. I'd like it to read in ten integers from the user and sort them from lowest to highest. I'd like most of the code to be unchanged- I don't think there is a massive problem- it's just getting a little confused?!?!