Description
design an application in which you declare an array of three strings and store three values in the array. write a try block in which you loop to display each successive element of the array, increasing a subscript by one on each pass through the loop. assume that an arrayindexoutofboundsexception is created automatically when a subscript is not correct for an array. create a catch block that catches any exception and displays the message now you've gone too far.
Explanation & Answer
public class ArrayBoundExceptionTest
public static void main()
//Declarations
num count = 0; // count variable is
used for subscript
string arr[3] = “Hello”, “Exception”, “World” // 3 string values stored in array
i.e. arr
try
// this loop used
to display each element of the array
while count<=3
// display the value of each element of array
output "The value of element of array is ", arr[count]
// increment in subscript by 1
count = count + 1;
endwhile
endtry
catch(ArrayIndexOutOfBoundsException
aioobe)
output “Now you've gone too far " // display Exception Message
output aioobe.getMessage()
endcatch
return
endClass
Review
Review
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Similar Content
Related Tags
Things That Matter
by Charles Krauthammer
Wuthering Heights
by Emily Brontë
Fear - Trump in the White House
by Bob Woodward
The Call of the Wild
by Jack London
12 Rules for Life
by Jordan Peterson
The Metamorphosis
by Franz Kafka
Death on the Nile
by Agatha Christie
The Eyes Were Watching God
by Zora Neale Hurston