Hi all together,
I have one problem about this task and one question.
First of all the problem: As far as I understood, when you pass the array variable to the sortieren() method, one does not pass the reference to this variable to the method, but rather copies its content and assigns it to the local variable inside the method. So how do I return then the sorted array from the sortieren() method back to the array in the main method? I would either not set sortieren() to void, but instead to String[] or I would put the System.out.println into the sortieren() method. Is there another way I am not aware of or how is the default code supposed to work?
And secondly the question, I got a solution for this problem but on a different way with Arrays.sort() and by using a Comparator (see code below). I have no clue, why I should use the istGroesser(), but I know there must be a (I believe very complicated) way to compare the Strings letter by letter while ignoring upper case letters. I don´t need a complete solution for that, but rather a detailed way on how to approach that problem from this different perspective.
Thanks a lot in advance!
package de.codegym.task.task08.task0830;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
Aufgabe zu Algorithmen
*/
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();
}
sortieren(array);
for (String x : array) {
System.out.println(x);
}
}
public static void sortieren(String[] array) {
//schreib hier deinen Code
}
// String-Vergleichsmethode: 'a' ist größer als 'b'
public static boolean istGroesserAls(String a, String b) {
return a.compareTo(b) > 0;
}
}