I have a project for class were I need to get 4 different strings inputted and then output them in alphabetical order.
So far I have this:
String wd1
boolean swapped = false;
do {
swapped = false;
if (w2.compareTo(w1) < 0) {
String tmp = w2;
w2 = w1;
w1 = tmp;
swapped = true;
}
if (w3.compareTo(w2) < 0) {
String tmp = w3;
w3 = w2;
w2 = tmp;
swapped = true;
}
if (w4.compareTo(w3) < 0) {
String tmp = w4;
w4 = w3;
w3 = tmp;
swapped = true;
}
} while (swapped)
System.out.println(w1);
System.out.println(w2);
System.out.println(w3);
System.out.println(w4);