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");

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter11: Exception Handling
Section: Chapter Questions
Problem 1CP
icon
Related questions
Question

new java code can only be added after line 17. 

The while loop reads values from input until an integer is read. Complete the exception handler in the while loop to catch an
Input MismatchException 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. InputMismatchException;
3
4 public class Cents {
5
1.000 a
6
7
8
9
10
11
12
13
14
15
PPP
16
67
17
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int numCents;
boolean valueFound = false;
while (!value Found) {
try {
}
numCents = scnr.nextInt();
valueFound= true;
System.out.println(numCents + " cents = + (numCents / 5) + nickels");
System.out.println("Processed one valid input value");
Tou
Transcribed Image Text:The while loop reads values from input until an integer is read. Complete the exception handler in the while loop to catch an Input MismatchException 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. InputMismatchException; 3 4 public class Cents { 5 1.000 a 6 7 8 9 10 11 12 13 14 15 PPP 16 67 17 public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int numCents; boolean valueFound = false; while (!value Found) { try { } numCents = scnr.nextInt(); valueFound= true; System.out.println(numCents + " cents = + (numCents / 5) + nickels"); System.out.println("Processed one valid input value"); Tou
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT