Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Whenever i enter something other than an int i get this error message. What can I do to change this to something that tells me
Whenever i enter something other than an int i get this error message. What can I do to change this to something that tells me to try again, if i were to enter anything other than 1 or 2. Enter your choice for first rank fg Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:864) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) public void game() { Scanner in = new Scanner(System.in); int count; int a = 0; for (int i = 0; i < 4; i++) { switch (i) { case 1: System.out.println("first"); a = in.nextInt(); break; case 2: System.out.println("second"); a = in.nextInt(); break; default: break; } count = i; if (count == 1) if (a != 1) { i = i - 1; System.out.println("Sorry"); } else System.out.println("Correct"); else if (count == 1) if (a != 2) { System.out.println("wrong"); } else System.out.println("Correct"); else if (count == 2) if (a != ) { System.out.println("wrong"); } else System.out.println("Correct"); } System.out.println("Game over);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started