for Loops

AP Computer Science A· difficulty 2/5

public static void printReverse(int[] a) {
    for (int i = /* missing */; i >= 0; i--) {
        System.out.println(a[i]);
    }
}

Which expression replaces /* missing */?

  • A

    a.length - 1

    check_circle
  • B

    a.length + 1

  • C

    a.length

  • D

    0

Explanation

The last valid index is a.length - 1. Iterate downward from there to 0.

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

Related questions