Note that there are some explanatory texts on larger screens.

plurals
  1. POoutput an error when someone enters a letter as a menu choice
    text
    copied!<p>I want to make this program output an error when someone enters a letter as a menu choice</p> <pre><code>package main; import java.util.Scanner; public class Main { Scanner input = new Scanner(System.in); public static void main(String[] args) { int UserIn = 0; double numberInputA; double numberInputB; double Answer; Scanner input = new Scanner(System.in); while (UserIn != 5) { System.out.println("What type of calculation would you like to perform?"); System.out.println("1. Add\n2. Subtract\n" + "3. Multiply\n4. Divide\n5. Exit"); UserIn = input.nextInt(); if (UserIn &gt; 5) { System.out.println("ERROR choose the numbers on the menu"); } else if (UserIn &lt; 1) { System.out.println("ERROR choose the numbers on the menu"); } if (UserIn &lt; 5) { System.out.println("Enter first number:"); numberInputA = input.nextDouble(); System.out.println("Enter second number"); numberInputB = input.nextDouble(); if (UserIn == 1) { Answer = numberInputA + numberInputB; System.out.println("Number 1 is:" + numberInputA); System.out.println("Number 2 is:" + numberInputB); System.out.println("Result is : " + Answer); System.out.println(""); } if (UserIn == 2) { Answer = numberInputA - numberInputB; System.out.println("Number 1:" + numberInputA); System.out.println("Number 2:" + numberInputB); System.out.println("Result is :" + Answer); System.out.println(""); } if (UserIn == 3) { Answer = numberInputA * numberInputB; System.out.println("Number 1:" + numberInputA); System.out.println("Number 2:" + numberInputB); System.out.println("Result is :" + Answer); System.out.println(""); } if (UserIn == 4) { Answer = numberInputA / numberInputB; System.out.println("Number 1:" + numberInputA); System.out.println("Number 2:" + numberInputB); System.out.println("Result is :" + Answer); System.out.println(""); } } if (UserIn == 5) { System.out.println("Program exited"); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload