Question: The while loop makes up to two attempts to read an integer divisible by 1 0 from input into numCents. Use multiple exception handlers to:
The while loop makes up to two attempts to read an integer divisible by from input into numCents. Use multiple exception
handlers to:
Catch an InputMismatchException, output "Unexpected input: The TotalCents program terminates", and assign triesLeft
with
Catch an Exception, output the message of the Exception, and subtract from triesLeft.
End each output with a newline.
Ex: If the input is then the output is:
Tries left:
Valid input: cents dimes
Ex: If the input is then the output is:
Tries left:
Unexpected input: The TotalCents program terminates
Ex: If the input is then the output is:
Tries left:
Amount cannot be converted to dimes
Tries left:
Valid input: cents dimes
import java.util.Scanner;
import java.util. InputMismatchException;
public class Totalcents
public static void mainString args
Scanner scnr new Scanner
System.in;
int numCents;
int triesLeft ;
while triesLeft
System.out.printlnTries left: triesLeft;
try
numCents scnrnextint ;
if numCents
throw new ExceptionAmount cannot be converted to dimes";
triesLeft ;
System.out.print Valid input: ;
System.out.printlnnumCents cents numCents dimes";
Your code goes here
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
