Ok so I don't understand the second half of line 34 what it does?
and my next problem when in the main method running gets to sort(array) it actually doesn't start it I mean the line42 doesn't start.
Thank you in advance your help, Tamas
package com.codegym.task.task09.task0930;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
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<>();
/*
while (true) {
String s = reader.readLine();
if (s.isEmpty()) {
break;
}
list.add(s);
}
*/
list.add("Cherry");
list.add("1");
list.add("Bob");
list.add("3");
list.add("Apple");
list.add("22");
list.add("0");
list.add("Watermelon");
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
ArrayList<String> strings = new ArrayList<>();
ArrayList<Integer>integers = new ArrayList<>();
for(int i = 0; i > array.length; i++) {
isNumber(array[i]);
if(array[i].equals(true)) {
integers.add(Integer.parseInt(array[i]));
} else {
strings.add(array[i]);
}
}
for (String y : strings) {
System.out.println(y);
}
for (Integer z : integers) {
System.out.println(z);
}
}
/*for(int i = 0; i < array.length -1; i++) {
if(isNumber(array[i])) {
for(int j = i+1; j < array.length; j++) {
if(isNumber(array[j])) {
int var1 = Integer.parseInt(array[i]);
int var2 = Integer.parseInt(array[j]);
isGreaterThan(array[i], array[j]);
}
}
}
for(int l = i + 1; l < array.length; l++) {
if(isNumber(array[l])) {
continue;
}
else {
isGreaterThan(array[i],array[l]);
}
}
}*/
// 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;
}
}