Question: Java Problems 1. ArrayIndexOutOfBoundsException Given the following code: public class ExceptionTest{ public static void main( String[] args ){ String nums[] = {one, two, three}; for(
Java Problems
1. ArrayIndexOutOfBoundsException
Given the following code:
public class ExceptionTest{
public static void main( String[] args ){
String nums[] = {one, two, three};
for( int i=0; i<=3; i++ ){
System.out.println(nums[i]);
}
}
}
Compile and run the TestExceptions program. The output should look like this:
one
two
three
Exception in thread "main"
java.lang.ArrayIndexOutOfBoundsException: 3
at ExceptionTest.main(1.java:4)
Modify the TestExceptions program to handle the exception. The output of the program after catching the exception should look like this:
one
two
three
Exception caught: Array Index 3 is out of bounds
2. Catching Exceptions
Implement Exception handling for the programs you have written in the laboratory exercises as listed below. Note that all data to be used for processing must be input data (data entry from the user). When an invalid data is entered, the program should loop back to data entry until the input becomes valid.
Sample Output:
run:
*******CIRCLE CALCULATOR*******
Enter the radius --> a
INVALID INPUT!
Enter the radius --> ?
INVALID INPUT!
Enter the radius --> 10
Result:
Area:314.0
Diameter:20.0
Circumference:62.800000000000004
BUILD SUCCESSFUL (total time: 20 seconds)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
