← Quiz: Java Arrays: all 10 questions
Quiz: Java Arrays · Question 6 of 10
What does this print? (code)
What does this print?
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int[] a = {42, 7, 19, 3};
Arrays.sort(a);
System.out.println(a[0] + a[a.length - 1]);
}
}
- A.49
- B.3
- C.45
- D.342
Answer & explanation
Correct answer: 45
After sorting, the array is [3, 7, 19, 42]. The first and last elements are 3 and 42, and 3 + 42 = 45.
Can you get the rest right without peeking?
Take the timed Quiz: Java Arrays quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →