Ask Question
11 October, 11:17

Use a switch statement to display "one" if the user has entered 1, "two" if the user has entered 2, and "three" if the user has entered 3. If a number other than 1, 2, or 3 is entered, the program should display an error message: "Enter one of the numbers - 1, 2, or 3."

+4
Answers (1)
  1. 11 October, 13:34
    0
    import java. util. Scanner;

    public class num5 {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("Enter one the numbers - 1, 2, or 3.");

    int num = in. nextInt ();

    switch (num) {

    case 1:

    System. out. println ("one");

    break;

    case 2:

    System. out. println ("two");

    break;

    case 3:

    System. out. println ("three");

    break;

    default:

    System. out. println ("Error");

    }

    }

    }

    Explanation:

    Using Java Programming Language User Scanner Class to prompt, receive and store user's input Use a switch statement with three cases as required by the question to output one, two or three Use the default statement to handle any other case
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Use a switch statement to display "one" if the user has entered 1, "two" if the user has entered 2, and "three" if the user has entered 3. ...” 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