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. InputMismatchException; 3 4 public class Cents { 5 6 7 8 9 10 11 12 13 14 15 16 public static void main(String[] args) { Scanner scnr new Scanner(System.in); int numCents; boolean valueFound = false; while (!valueFound) { try { numCents scnr.nextInt(); valueFound=true; System.out.println(numCents + "cents = " + (numCents / 5) + nickels"); System.out.println("Processed one valid input value");
import java.util.Scanner;
import java.util.InputMismatchException;
public class Cents {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int numCents;
boolean valueFound = false;
while (!valueFound) {
try {
numCents = scnr.nextInt();
valueFound = true;
System.out.println(numCents + " cents = " + (numCents / 5) + " nickels");
System.out.println("Processed one valid input value");
}
/******************************************************************************************************* New Java Code can only be added here. No other code can be edited
******************************************************************************************************/
}
}
}
![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. InputMismatchException;
3
4 public class Cents {
5 public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int numCents;
boolean valueFound
1010 00
6
7
8
9
10
11
12
13
14
15
16
17
18
=
while (!value Found) {
try {
}
false;
numCents scnr.nextInt ();
valueFound = true;
System.out.println(numCents + "cents = + (numCents / 5) + nickels");
System.out.println("Processed one valid input value");](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F0cc153ae-b205-4fb2-9991-7cf6a21d5016%2F6b67975f-5fb9-4f65-9f6c-bc0d26cc2d2a%2F33a8znq_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images









