Answered step by step
Verified Expert Solution
Question
1 Approved Answer
5 6 7 8 9 le 11 12 13 14 In the Code below, you are given a java class X, which contains a throwlt()
5 6 7 8 9 le 11 12 13 14 In the Code below, you are given a java class X, which contains a throwlt() method and a main method. The main method reads a value from the user, converts it into an integer and then uses it to call the throwlt() method. Decide whether the answers below are correct or not. Write a short explanation as to why. (Unjustified or incorrectly justified answers will not be accepted.) 1 import java.util.Scanner; 2 3 public class X{ public static void throwIt(int input) throws Exception { if (input == 1) throw new RuntimeException(); else if (input == 2) return; else if (input == 3) { int x = ; int y = 5 / x; } else if (input == 4) throw new Exception(); } 15 16e public static void main(String[] args) { try { Scanner scan = new Scanner(System.in); int value = Integer.parseInt(scan.next(); throwit(value); } catch (Number FormatException ne) { 22 System.out.print("Not valid "); } catch (ArithmeticException ae) { System.out.print(" Arithmetic Exception "); } catch (Exception re) { System.out.print("caught "); } finally { System.out.print("finally "); 29 } System.out.println("after"); } 32 } 7 * A B 1 = = 17 18 19 20 21 23 24 25 26 27 28 30 31 *** Don't delete the questions. Please only write your answers. *** a) If the program is executed with parameter "1", the output will be "finally after". b) If the program is executed with parameter "2", the output will be "finally after": c) If the program is executed with parameter "Not_a_number", the execution of the program stops printing an error message after printing "Not valid finally after d) If the program is executed with parameter "3", the output will be "Arithmetic Exception after". le) If the program is executed with parameter "4", the output will be "caught finally after
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started