Ask Question

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

+4
Answers (2)
  1. 12 April, 09:22
    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.
  2. 12 April, 09:25
    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
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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers