← Quiz: Pagination and Sorting: all 10 questions
Quiz: Pagination and Sorting · Question 3 of 10
What does this print? (code)
What does this print?
import java.util.*;
public class Main {
public static void main(String[] args) {
List<String> all = List.of("a", "b", "c", "d", "e", "f", "g");
int size = 3, page = 2;
int from = Math.min(page * size, all.size());
int to = Math.min(from + size, all.size());
System.out.println(all.subList(from, to) + " " + (int) Math.ceil(all.size() / (double) size));
}
}
- A.[g, h, i] 3
- B.[d, e, f] 3
- C.[g] 2
- D.[g] 3
Answer & explanation
Correct answer: [g] 3
Page 2 starts at offset 6, so only "g" is left; 7 items in pages of 3 is 3 pages.
Can you get the rest right without peeking?
Take the timed Quiz: Pagination and Sorting quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →