🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Scheduling and Async: all 10 questions

Quiz: Scheduling and Async · Question 5 of 10

What does this print? (code)

What does this print?

public class Main {
    public static void main(String[] args) {
        int period = 5;
        int[] durations = {2, 8, 2};
        int end = 0;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < durations.length; i++) {
            int start = Math.max(i * period, end);
            sb.append(start).append(' ');
            end = start + durations[i];
        }
        System.out.println(sb.toString().trim());
    }
}
  1. A.0 5 10
  2. B.0 5 13
  3. C.0 7 17
  4. D.0 2 10
Answer & explanation

Correct answer: 0 5 13

Run 2 starts at 5 and ends at 13, later than the planned 10, so run 3 starts at 13.

Can you get the rest right without peeking?

Take the timed Quiz: Scheduling and Async quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →