Test: Computer Science

1.

Consider the Array

int[] arr = {1, 2, 3, 4, 5};

What are the values in arr after the following code is executed?

for (int i = 0; i < arr.length - 2; i++)
{
int temp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = temp;
}

12345

15432

54321

OutOfBoundsException

23451

1/4 questions

0%
Learning Tools by Varsity Tutors