Question: Question 1.In a Try / Catch / Finally block, what type of code goes in each block? In other words, what is the purpose of

Question 1.In a Try / Catch / Finally block, what type of code goes in each block? In other words, what is the purpose of the code in each block?

Try { Which code goes here?

} Catch {

Which code goes here?

} Finally {

Which code goes here?

}

Question 2.

Determine the output of the following code when the input is: (Provide a response for values A, B and C.) a) 1 b) 0 c) 12XY

Scanner scanner = new Scanner(System.in);

try {

int num = scanner.nextInt();

if (num != 0) {

throw new Exception("Not zero");

}

System.out.println("I'm happy with the input.");

} catch (InputMismatchException e) {

System.out.println("Invalid Entry");

} catch (Exception e) {

System.out.println("Error: " + e.getMessage());

}

Question 4:

What will be the output from the following code?

StringBuffer word1, word2;

word1 = new StringBuffer(Lisa);

word2 = word1;

word2.insert(0, Mona );

System.out.println(word1);

Question 3.Determine the output of the following code when the input is: (This is similar to Exercise 1, but the code here has the finally clause.) a) 1 b) 0 c) 12XY

Scanner scanner = new Scanner(System.in);

try {

int num = scanner.nextInt();

if (num != 0) {

throw new Exception("Not zero");

}

System.out.println("I'm happy with the input.");

} catch (InputMismatchException e) {

System.out.println("Invalid Entry");

} catch (Exception e) {

System.out.println("Error: " + e.getMessage());

} finally {

System.out.println("Finally Clause Executed");

}

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!