"The sort() method should call the isGreaterThan() method." -> it is not in the conditions, that I have to use it
package com.codegym.task.task09.task0930;
//import com.sun.java.util.jar.pack.ConstantPool;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;
/*
Task about algorithms
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<String>();
while (true) {
String s = reader.readLine();
if (s.isEmpty()) break;
list.add(s);
}
String[] array = list.toArray(new String[list.size()]);
sort(array);
for (String x : array) {
System.out.println(x);
}
}
public static void sort(String[] array) {
// write your code here
String ertek = null;
boolean joszar = true;
int j = 0;
int k = 0;
ArrayList<Integer> arraylist1 = new ArrayList<Integer>();
ArrayList<String> arrayList2 = new ArrayList<String>();
ArrayList<String> arrayList3 = new ArrayList<String>();
// számokból, vagy sztringből áll-e a cucc
for (int i = 0; i < array.length; i++) {
ertek = array[i];
joszar = isNumber(ertek);
if (joszar == true) {
arraylist1.add(Integer.parseInt(ertek));
} else {
arrayList2.add((ertek));
}
}
Collections.sort(arraylist1, Collections.reverseOrder());
Collections.sort(arrayList2);
for (int i = 0; i < array.length; i++) {
ertek = array[i];
joszar = isNumber(ertek);
if (joszar == true) {
arrayList3.add(i, Integer.toString(arraylist1.get(j)));
j = j + 1;
} else {
arrayList3.add(i, arrayList2.get(k));
k = k + 1;
}
}
for (int i = 0; i < arrayList3.size(); i++) {
array[i] = arrayList3.get(i);
}
}
// String comparison method: 'a' is greater than 'b'
public static boolean isGreaterThan(String a, String b) {
return a.compareTo(b) > 0;
}
// Is the passed string a number?
public static boolean isNumber(String s) {
if (s.length() == 0) return false;
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
if ((i != 0 && c == '-') // The string contains a hyphen
|| (!Character.isDigit(c) && c != '-') // or is not a number and doesn't start with a hyphen
|| (i == 0 && c == '-' && chars.length == 1)) // or is a single hyphen
{
return false;
}
}
return true;
}
}