Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- // asks the user for two words then check to see if the two strings are equal.
- // assuming the two words are different print them out in the correct alphabetic
- // order
- // repeats if user says no
- Scanner scan = new Scanner(System.in);
- outer: do {
- System.out.println("Please enter TWO words");
- String wordOne = scan.nextLine();
- String wordTwo = scan.nextLine();
- int compare = wordOne.compareToIgnoreCase(wordTwo);
- if (!wordOne.equalsIgnoreCase(wordTwo)) {
- System.out.println("They are not equal!");
- if (compare < 0) {
- System.out.println(wordOne + " comes before " + wordTwo);
- } else if (compare > 0) {
- System.out.println(wordTwo + " comes before " + wordOne);
- }
- } else {
- System.out.println("They are the same...");
- }
- do {
- System.out.println("Do you want to try again? y/n");
- String cont = scan.nextLine();
- if (cont.equalsIgnoreCase("n")) {
- System.out.println("Thank you for using the program!");
- break outer;
- } else if (cont.equalsIgnoreCase("y")) {
- break;
- } else {
- System.out.println("INVALID, please enter y/n");
- }
- } while (true);
- } while (true);
- System.out.println("The End");
- scan.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement