While loop comparing strings from user
write a short program which will run in a loop asking the user for input with a simple prompt (for example "-> "). This will run until the user hits the enter key with no input (entering a String of length 0). The program will then display the lowest and highest (in alphabetical order) of the entered Strings. For example running the program might show:
> Four score and
-> seven years ago
-> our fathers brought
-> forth on this continent
-> a new nation.
first: a new nation.
last: seven years ago
This is what I have to do.
That is what I have. I can get it to terminate when str1 or str2 is empty. I dont know how I can somehow scan the user input into a string that stays constant. I can get it to compare strings but it sorta screws up my code. If it comes to it I'll end up turning in bass ackwards code over nothing. Any help is appreciated. Thanks
public class StringReader
static String str1, str2;
public static void main(String args)
Scanner scan = new Scanner(System.in);
Boolean strLength = true;
String first = "first";
String last = "last";
str1 = scan.nextLine();
str2 = scan.nextLine();
if (str1.isEmpty() || str2.isEmpty())
strLength = false;
System.out.println("First: " + first);
System.out.println("Last: " + last);