Developing Algorithms Using Arrays

AP Computer Science A· difficulty 3/5

String[] names = {"Ann", "Bob", "Cy"};
int[] scores = {85, 92, 77};
int idx = 1;
System.out.println(names[idx] + ":" + scores[idx]);

What is printed?

  • A

    Bob:85

  • B

    Ann:85

  • C

    Cy:77

  • D

    Bob:92

    check_circle

Explanation

In parallel arrays, the same index refers to corresponding entries. names[1] = "Bob" and scores[1] = 92.

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

Related questions