class Exercise4 { // sort array a in ascending order using the "selection sort" algorithm public static void sort(int[] a) { int n = a.length; int i = n; while (i > 1) { int j = maximum(a, i); i = i-1; if (i != j) { int e = a[i]; a[i] = a[j]; a[j] = e; } } } // returns position of greatest element in the first n elements of a public static int maximum(int[] a, int n) { int p = n-1; int m = a[p]; int i = p-1; while (i >= 0) { if (a[i] > m) { p = i; m = a[p]; } i = i-1; } return p; } }