for Loops

AP Computer Science A· difficulty 3/5

int[] arr = {4, 2, 9, 1, 6};
int min = arr[0];
for (int i = 1; i < arr.length; i++) {
  if (arr[i] < min) {
    min = arr[i];
  }
}
System.out.println(min);

What is printed?

  • A

    0

  • B

    4

  • C

    1

    check_circle
  • D

    2

Explanation

The loop tracks the smallest value: starts at 4, then 2, keeps 2 (vs 9), then to 1 (vs 2), keeps 1 (vs 6). Final min is 1.

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

Related questions