I capitalized and trimmed all words, but still not correct! where is the mistake here?
package com.codegym.task.task08.task0830;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
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) {
//write your code here
int length = array.length;
for (int i = 0; i < length-1; i++) {
String tM = array[i];
for (int j = i + 1; j < length; j++) {
String nM = array[j];
if (isGreaterThan(tM.toLowerCase().trim(), nM.toLowerCase().trim())) {
array[i] = nM;
array[j] = tM;
nM = tM;
}
}
}
}
// String comparison method: 'a' is greater than 'b'
public static boolean isGreaterThan(String a, String b) {
return a.compareTo(b) > 0;
}
}