Weiss jemand den Lösungsweg dazu?
Danke
package de.codegym.task.task09.task0930;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Aufgabe zu Algorithmen
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> liste = new ArrayList<String>();
while (true) {
String s = reader.readLine();
if (s.isEmpty()) break;
liste.add(s);
}
String[] array = liste.toArray(new String[liste.size()]);
sortieren(array);
for (String x : array) {
System.out.println(x);
}
}
public static void sortieren(String[] array) {
//schreib hier deinen Code
int size = array.length;
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < array.length; j++) {
if ((istZahl(array[i]) && istZahl(array[j])) && (!istGroesserAls(array[i], array[j]))) {
String temp = array[i];
array[i] = array[j];
array[j] = temp;
}
else if (istGroesserAls(array[i], array[j])) {
String temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
}
// String-Vergleichsmethode: 'a' ist größer als 'b'
public static boolean istGroesserAls(String a, String b) {
return a.compareTo(b) > 0;
}
// Ist die übergebene Zeichenkette eine Zahl?
public static boolean istZahl(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 == '-') // Die Zeichenkette enthält einen Bindestrich
|| (!Character.isDigit(c) && c != '-') // oder ist keine Zahl und beginnt nicht mit einem Bindestrich
|| (i == 0 && c == '-' && chars.length == 1)) // oder ist ein einzelner Bindestrich
{
return false;
}
}
return true;
}
}