Traversing Arrays

AP Computer Science A· difficulty 2/5

String[] s = {"x", "y", "z"};
for (int i = 0; i < s.length; i++) {
  System.out.print(i + ":" + s[i] + " ");
}

What is printed?

  • A

    0:x 1:y 2:z

    check_circle
  • B

    x:0 y:1 z:2

  • C

    1:x 2:y 3:z

  • D

    0:x 1:y 2:z

Explanation

Indices start at 0. Note the trailing space after each printout, including after z.

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

Related questions

AP Computer Science A · Traversing Arrays Practice Question | Acemy