🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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());
    }
}
  1. A.10 10
  2. B.6 6
  3. C.6 10
  4. 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 →