Question: our goal is to take the following code and convert it to use exception handling, rather than if-statements. Use an ArrayIndexOutOfBoundsException. import java.util.Scanner; public class

our goal is to take the following code and convert it to use exception handling, rather than if-statements. Use an ArrayIndexOutOfBoundsException.

import java.util.Scanner;

public class Handling {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int[] array = {11,33,55,77,99,22,44,66,88,10};

//Prompt the user to enter an array spot [0-9].

System.out.print("Enter a spot in the array and I will return the value[0-9]: ");

int index = input.nextInt();

if(index >= 0 && index <= 9) {

System.out.println("Your value at index " + index + " is " + array[index] + "!");

}

else {

System.out.println("Bad index!");

}

}

}

What exception type does the following program throw?

publicclassTest{

public static void main(String[] args) {

int[] list = new int[5];

System.out.println(list[5]);

}

}

A. ArithmeticException

B. ArrayIndexOutOfBoundsException

C. StringIndexOutOfBoundsException

D. ClassCastException

E. No exception

What exception type does the following program throw?

publicclassTest{

public static void main(String[] args) {

Object o = null;

System.out.println(o.toString());

}

}

A. ArithmeticException

B. ArrayIndexOutOfBoundsException

C. StringIndexOutOfBoundsException

D. ClassCastException

E. NullPointerException

What is displayed on the console when running the following program?

classTest{

public static void main(String[] args) {

try {

System.out.println("Welcome to Java");

int i = 0;

int y = 2/i;

System.out.println("Welcome to Java");

}

catch (ArithemticException ex) {

System.out.println("Welcome to Java");

}

finally {

System.out.println("End of the block");

}

}

}

A. The program displays Welcome to Java three times followed by End of the block.

B. The program displays Welcome to Java two times followed by End of the block.

C. The program displays Welcome to Java three times.

D. The program displays Welcome to Java two times.

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 Programming Questions!