← Quiz: Java Streams in Depth: all 10 questions
Quiz: Java Streams in Depth · Question 7 of 10
What does this print? (code)
What does this print?
import java.util.stream.*;
public class Main {
public static void main(String[] args) {
System.out.println(IntStream.range(1, 4).sum() + " " + IntStream.rangeClosed(1, 4).sum());
}
}
- A.10 10
- B.6 6
- C.6 10
- D.10 6
Answer & explanation
Correct answer: 6 10
range(1, 4) is 1, 2, 3 (sum 6); rangeClosed(1, 4) also includes 4 (sum 10).
Can you get the rest right without peeking?
Take the timed Quiz: Java Streams in Depth quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →