I do not have idea where i can find some information to push forward this task.
It is really so easy, where in help_forum is only two people asking for help, and any of them do not receive precision hints.
Someone says use Bubble sort, but after that everything is mixed in my head.
Someone use ArrayList and i try go this path too.
For testing, I assigned 20 words rigidly so as not to slap them every time.
My first idea, is to get char index "char charAt(index)" from first letter of String in tablica[] and saving it in second table_2. Sorting this using Bubble and after that match table[] to table2[].
And i realize i don't know what i'm doing... :( really.
package pl.codegym.task.task08.task0830;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
/*
Zadanie z algorytmami
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String[] tablica = new String[20];
tablica[0] = "name"; //from here test
tablica[1] = "cast";
tablica[2] = "back";
tablica[3] = "women";
tablica[4] = "man";
tablica[5] = "cow";
tablica[6] = "feather";
tablica[7] = "animal";
tablica[8] = "skin";
tablica[9] = "wax";
tablica[10] = "earth";
tablica[11] = "whip";
tablica[12] = "statement";
tablica[13] = "toes";
tablica[14] = "basket";
tablica[15] = "women";
tablica[16] = "coat";
tablica[17] = "breath";
tablica[18] = "vase";
tablica[19] = "horses";
for (String x : tablica) {
System.out.println(x);
}
System.out.println("..."); // to here test, delete it after
/* for (int i = 0; i < tablica.length; i++) { //task req dont forget uncomment!
tablica[i] = reader.readLine();
}
*/
sortuj(tablica);
for (String x : tablica) {
System.out.println(x);
}
}
public static void sortuj(String[] tablica) {
//tutaj wpisz swój kod
/* ArrayList<String> lista = new ArrayList<>();
for(int i=0; i < tablica.length-1; i++) {
lista.add(tablica[i]);
}
*/
String a = tablica[0];
String b = tablica[19];
isWiekszeOd(a ,b);
/*
int temp = 0;
for(int i=0; i < tablica.length-1; i++){
for(int j=0; j < (tablica.length-1); j++){
if(tablica[j+1] > tablica[j]){
//swap elements
temp = tablica[j+1];
tablica[j+1] = tablica[j];
tablica[j] = temp;
}
}
}
*/
}
// Metoda porównywania ciągów: 'a' jest większe niż 'b'
public static boolean isWiekszeOd(String a, String b) {
return a.compareTo(b) > 0;
}
}