The while loop reads values from input until an integer is read. Complete the exception handler in the while loop to catch an InputMismatchException exception and: • Output "Removed unacceptable input for number of cents". End with a newline. • Discard the invalid input. Ex: If the input is 20 60, then the output is: 20 cents = 4 nickels Processed one valid input value Ex: If the input is Aya Tia 20 60, then the output is: Removed unacceptable input for number of cents Removed unacceptable input for number of cents 20 cents = 4 nickels Processed one valid input value Note: Each value read from input is on one line. 1 import java.util.Scanner; 2 import java.util.Input MismatchException; 3 4 public class Cents { 4567 5 public static void main(String[] args) { Scanner scnr = new Scanner (System.in); int numCents; boolean valueFound = false; 7 8 9 3456 WNHO6 10 11 12 13 14 15 16 17 while (!valueFound) { try { numCents = scnr.nextInt (); valueFound = true; System.out.println(numCents + "cents = " + (numCents / 5) + " nickels"); System.out.println("Processed one valid input value");
The while loop reads values from input until an integer is read. Complete the exception handler in the while loop to catch an InputMismatchException exception and: • Output "Removed unacceptable input for number of cents". End with a newline. • Discard the invalid input. Ex: If the input is 20 60, then the output is: 20 cents = 4 nickels Processed one valid input value Ex: If the input is Aya Tia 20 60, then the output is: Removed unacceptable input for number of cents Removed unacceptable input for number of cents 20 cents = 4 nickels Processed one valid input value Note: Each value read from input is on one line. 1 import java.util.Scanner; 2 import java.util.Input MismatchException; 3 4 public class Cents { 4567 5 public static void main(String[] args) { Scanner scnr = new Scanner (System.in); int numCents; boolean valueFound = false; 7 8 9 3456 WNHO6 10 11 12 13 14 15 16 17 while (!valueFound) { try { numCents = scnr.nextInt (); valueFound = true; System.out.println(numCents + "cents = " + (numCents / 5) + " nickels"); System.out.println("Processed one valid input value");
Chapter11: Exception Handling
Section: Chapter Questions
Problem 1CP
Related questions
Question
new java code can only be added after line 17.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT