Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

In Exercise Let U = {x x N and x Answered: 1 week ago

Answered: 1 week ago

Question

1. Design an effective socialization program for employees.

Answered: 1 week ago