Question: Write a program that prompts the user to read two integers and displays their sum. If anything but an integer is passed as input,
Write a program that prompts the user to read two integers and displays their sum. If anything but an integer is passed as input, your program should catch the Input MismatchException that is thrown and prompt the user to input another number by printing "Please enter an integer." SAMPLE RUN #1: java InputMismatch Interactive Session Standard Input Standard Error (empty) Standard Output Hide Invisibles Highlight: NoneStandard Input OnlyPrompts OnlyStandard Output w/o PromptsFull Standard OutputAllShow Highlighted Only Enter-an-integer:2.5. Please enter-an-integer. Enter-an-integer-4.6. Please enter-an-integer. Enter-an-integer:hello! < Please enter-an-integer. Enter-an-integer:7- Enter-an-integer:5.6- Please enter-an-integer. Enter-an-integer:9.4 Please enter-an-integer. Enter an integer:10 17
Step by Step Solution
3.44 Rating (151 Votes )
There are 3 Steps involved in it
import javautilInputMismatchException import javautilScanner public class InputMismatch p... View full answer
Get step-by-step solutions from verified subject matter experts
