Question: Write a Java program (IME.java) that prompts the user to read two integers and displays their sum. Your program should kepp prompting the user to

 Write a Java program (IME.java) that prompts the user to read

Write a Java program (IME.java) that prompts the user to read two integers and displays their sum. Your program should kepp prompting the user to the read the number again if the input is invalid. Note that the nextInt method of the Scanner class will throw InputMismatchException if the one being read is not an integer. Use printStackTrace method of the exception object to display the trace of where exception occurs. Note that Java has two standard output streams, i.e., System.out and System.err. printStackTrace method uses the latter. Use the same output stream if you want synchronized output. Sample Output Enter two integers: 12.5 java.util.InputMismatchException at java.base/java.util.Scanner.throwFor (Scanner.java:939) at java.base/java.util.Scanner.next (Scanner.java:1594) at java.base/java.util.Scanner.nextInt (Scanner.java:2258) at java.base/java.util.Scanner.nextInt (Scanner.java:2212) at IME.main(IME.java:27) Incorrect input and re-enter two integers: abc 123 java.util. InputMismatchException at java.base/java.util.Scanner.throwFor (Scanner.java:939) at java.base/java.util.Scanner.next (Scanner.java:1594) at java.base/java. util.Scanner.nextInt (Scanner.java:2258) at java.base/java.util.Scanner.nextInt (Scanner.java:2212) at IME.main(IME.java:26) Incorrect input and re-enter two integers: 12 Sum is 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!