Developing Algorithms Using Arrays

AP Computer Science A· difficulty 2/5

int[] a = {1, 2, 3, 4};
int t = a[0];
a[0] = a[3];
a[3] = t;

What is the array after?

  • A

    {4, 2, 3, 1}

    check_circle
  • B

    {4, 4, 3, 1}

  • C

    {1, 2, 3, 4}

  • D

    {1, 4, 3, 4}

Explanation

Indices 0 and 3 are swapped using a temp variable.

Want 10 more like this — adaptive to your weak spots?

Related questions