You do not compare the value of the rows in the array:
if (inner < minimumIndex) {
minimumIndex = inner;
}
Perhaps you need this (if you want to sort the strings by int
String value ):
if (Integer.parseInt(array[inner]) < Integer.parseInt(array[minimumIndex])) {
minimumIndex = inner;
}
Tested Code:
public static void sort(String[] array) {
int outer = 0;
while (outer < array.length - 1) {
int minimumIndex = outer;
int inner = outer + 1;
while (inner < array.length) {
if (Integer.parseInt(array[inner]) < Integer.parseInt(array[minimumIndex])) {
minimumIndex = inner;
}
inner++;
}
String temp = array[minimumIndex];
array[minimumIndex] = array[outer];
array[outer] = temp;
outer++;
}
}
If you want to sort it by line:
if (array[inner].compareTo(array[minimumIndex]) < 0) {
minimumIndex = inner;
}