Ask Question
1 September, 02:29

Write an if-else statement that prints "Goodbye" if userString is "Quit", else prints "Hello". End with newline.

+4
Answers (2)
  1. 1 September, 03:30
    0
    import java. util. Scanner;

    public class DetectWord {

    public static void main (String [] args) {

    Scanner scnr = new Scanner (System. in);

    String userString;

    userString = scnr. next ();

    if (userString. equals ("Quit")) {

    System. out. println ("Goodbye");

    }

    else{

    System. out. println ("Hello");

    }

    }

    }

    This actually works for anything written and will provide the proper outcome for zybooks
  2. 1 September, 06:27
    0
    If you are using Java then the IF statement would be:

    If (userSting = = "Quit") {

    System. out. println ("Goodbye");

    }

    else

    System. out. println ("Hello");

    The IF statement will check whether the users input is the word "Quit". If the word is indeed "Quit" then the program will output the word "Goodbye". The ELSE statement on the other hand will only be displayed if the user inputs any other string than "Quit". The program will then output the word "Hello" any other string or number is inputted by the user.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write an if-else statement that prints "Goodbye" if userString is "Quit", else prints "Hello". End with newline. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers