Traversing Arrays

AP Computer Science A· difficulty 1/5

int[] a = {10, 20, 30};
for (int x : a) {
  System.out.print(x + " ");
}

What is printed?

  • A

    10 20 30

    check_circle
  • B

    10 20 30

  • C

    30 20 10

  • D

    0 1 2

Explanation

The for-each loop prints each element followed by a space, in order. Note: a trailing space is included after 30.

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

Related questions