Hi, my output is ordered, but i still get the last requirement false. Why?
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) {
for (int i = 0; i < array.length; i++)
{
for (int j = 0; j < array.length - 1; j++)
{
if (isGreaterThan(array[j], array[j+1]))
{
String aux = array[j+1];
array[j+1] = array[j];
array[j] = aux;
}
}
}
}
// String comparison method: 'a' is greater than 'b'
public static boolean isGreaterThan(String a, String b) {
char ac = a.charAt(0);
char bc = b.charAt(0);
if (ac == bc){
ac = a.charAt(1);
bc = b.charAt(1);
}
if (ac == bc){
ac = a.charAt(2);
bc = b.charAt(2);
}
if (ac > bc || a.compareTo(b)>0)
return true;
else
return false;
}
}