Question: 8. Consider the following Java code fragment: begin{tabular}{l} Scanner scanner = new Scanner(System.in); System. out.print(Enter First Number:); int a = scanner.nextint(); System.

8. Consider the following Java code fragment: \begin{tabular}{l} Scanner scanner = new Scanner(System.in); \\ System. out.print("Enter First Number:"); \\ int a = scanner.nextint(); \\ System. out. print("Enter First Second: "); \\ int b = scanner. nextint(); \\ int result = a + b; \\ System. out.println("Result:" + result); \\ \hline \end{tabular} a) What will happen if a user input other than numbers and why? (3 marks) b) How to prevent 8 (a) from happening? Describe your answer. (3 marks) c) Rewrite the code fragment with the solution described in 8 (b). Make sure that the program displays the error message "Wrong use of data type" if the user enters the wrong data type
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
