Ask Question
4 March, 13:28

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

+1
Answers (2)
  1. 4 March, 14:35
    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. 4 March, 15:32
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers