Question: The while loop makes multiple attempts to read a positive integer from input into cylinderLength. Use multiple exception handlers to: Catch an InputMismatchException, output Fatal
The while loop makes multiple attempts to read a positive integer from input into cylinderLength. Use multiple exception handlers to:
Catch an InputMismatchException, output "Fatal error: The CylinderLength program terminates", and assign tryAgain with false.
Catch an Exception and output the message of the Exception. import java.util.Scanner;
import java.util.InputMismatchException;
public class CylinderLength
public static void mainString args
Scanner scnr new ScannerSystemin;
int cylinderLength;
boolean tryAgain true;
while tryAgain
try
cylinderLength scnrnextInt;
if cylinderLength
throw new ExceptionCylinders length in cm must be positive";
tryAgain false;
System.out.printValid input: ;
System.out.printlnCylinders length in cm is cylinderLength;
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
