• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array index out of bounds question  RSS feed

 
Ollie Dee
Greenhorn
Posts: 10
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this question from last semester which im hoping someone could help me with.

Develop a new Exception Class called InvalidIndexException which will inform the user of an attempt to access an invalid index in an array.

Then give a Java method only called getValue which takes 2 parameters, an integer (I) representing the subscript and an integer Array (A), and returns the element at position I in the Array A. This method should throw an InvalidIndexException if I is not a valid index in the Array A.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The assignment tells you exactly what to do. What did you try? What exactly are you having trouble with?

An exception is a class just like any other class, that extends java.lang.Exception.

The second part tells you to create a method and the assignment tells you exactly what the name should be and the parameters, return type and what exception it should declare.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!