Im trying to make a persons name be printed in alphabetical/reverse alphabetical order. I have this so far:
Scanner name = new Scanner(System.in);
String N1;
String N2;
String N3;
double az_za;
System.out.print("First name: ");
N1 = name.nextLine();
System.out.print("Middle name: ");
N2 = name.nextLine();
System.out.print("Last name: ");
N3 = name.nextLine();
System.out.print("Enter 1 (alphabetical order) or 2 (reverse alphabetical order):");
az_za = name.nextDouble();
String names[] = {N1, N2, N3}
Ive tried using a string but i wasnt sure where to go with that as you can see. I also tried using
if (N1.compareTo(N2) < 0) && (N1.compareTo(N3) < 0)
but i wasnt sure what to put in the {} as in what do I put equal to what to isolate the names alphabetically.
I HAVE TRIED EVERYTHING MY ABILITIES ALLOW. I researched and looked up so many things but none helped my case, so dont say "what have you tried, were not gonna do your homework for you". Btw I also tried using arrays and char(?) but we havent learned that in class so i dont think we can use those.
TY in advance
EDIT:
Ok so i think i got it:
String names[] = {N1, N2, N3};
if (az_za == 1) {
Arrays.sort(names);
} else if (az_za == 2) {
Arrays.sort(names, Collections.reverseOrder());
From here it all compiles but im not sure what to put in the actual print statements here "____"
if (az_za == 1) {
System.out.println("Your name in alphabetical order is " + __________);
}if (az_za == 2) {
System.out.println("Your name in reverse alphabetical order is " +_____________);
Because if i put what was in the Arrays.sort(HERE) its a mess...