int[] arr = {3, 7, 2, 8, 5};
int max = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
System.out.println(max);What is printed?
- Acheck_circle
8
- B
7
- C
3
- D
5
Explanation
The loop tracks the largest value seen. It updates max to 7 (vs 3), then keeps 7 (vs 2), then to 8 (vs 7), then keeps 8 (vs 5). Final max is 8.