Given: 12. import java.util.*; 13. public class Explorer1 { 14. public static vo
ID: 3914000 • Letter: G
Question
Given:
12. import java.util.*;
13. public class Explorer1 {
14. public static void main(String[] args) {
15. TreeSet<Integer> s = new TreeSet<Integer>();
16. TreeSet<Integer> subs = new TreeSet<Integer>();
17. for(int i = 606; i < 613; i++)
18. if(i%2 == 0) s.add(i);
19. subs = (TreeSet)s.subSet(608, true, 611, true);
20. s.add(609);
21. System.out.println(s + " " + subs);
22. }
23. }
What is the result?
A. Compilation fails.
B. An exception is thrown at runtime.
C. [608, 609, 610, 612] [608, 610]
D. [608, 609, 610, 612] [608, 609, 610]
E. [606, 608, 609, 610, 612] [608, 610]
F. [606, 608, 609, 610, 612] [608, 609, 610]
Explanation / Answer
Answer: Option F. [606, 608, 609, 610, 612] [608, 609, 610]
Explanation:
In the first for loop set s is added with 606 608 610 612 and sub is the subset of s which shares the same memory as s.
then 609 is added to s. since subs and s shares the same memory when 609 is added to s and 609 is a subset; Then 609 is added to subs also.
So the output is [606, 608, 609, 610, 612] [608, 609, 610]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.