Question: 21. Consider the following code: Int[] array = new int[ ]; Int index; //assume that array is filled with values here //assume that the user

21. Consider the following code:

Int[] array = new int[];

Int index;

//assume that array is filled with values here

//assume that the user enters a value for index here

If ((index >=))&&(index<= array. Length)){

System.out.println(array[index]);

}

When could this code throw an exception?

A. When index is less than0. (my answer)

B. When index is equal to 0.

C. When index is greater that array.length.

D. When index is equal to array. length. (correct answer)

E. This code cannot throw an exception because the if statement prevents it.

Why is D the correct answer?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!