My program is displaying correct output but still 4th and 5th condition is not satisfied.Please help me to find the error in the program.
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 String[] sort(String[] array) {
for(int i=0; i<array.length-1;i++){
for(int j=i+1; j<array.length;j++){
String temp=" ";
boolean bool= isGreaterThan(array[i],array[j]);
if(bool==true){
temp=array[i];
array[i]= array[j];
array[j]= temp;}
//write your code here
}
}
return array ;
}
// String comparison method: 'a' is greater than 'b'
public static boolean isGreaterThan(String a, String b) {
return a.compareTo(b) > 0;
}
}