So my code alphabetizes the array except for the word "Ten" which ends up at the top. Can anyone explain why to me? thanks in advance
package com.codegym.task.task08.task0830;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.lang.reflect.Array;
import java.lang.*;
/*
Task about algorithms
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String[] array = new String[20];
for (int i = 0; i < array.length; i++) {
array[i] = reader.readLine();
}
sort(array);
for (String x : array) {
System.out.println(x);
}
}
public static void sort(String[] array) {
for(int i = 0; i < array.length; i ++){
for(int j = 1; j < array.length - 1; j++){
String first = array[i].substring(0, 1);
String second = array[j].substring(0, 1);
if(isGreaterThan(second, first) == true){
String temp = array[j];
array[j] = array[i];
array[i] = temp;
}
}
}
}
// String comparison method: 'a' is greater than 'b'
public static boolean isGreaterThan(String a, String b) {
return a.compareTo(b) > 0;
}
}