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;
}

23451

12345

OutOfBoundsException

54321

15432

1/4 questions

0%
Learning Tools by Varsity Tutors