programming logic and design

User Generated

jnlare2797

Computer Science

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.

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

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



Anonymous
Excellent resource! Really helped me get the gist of things.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags