Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Which of the code segments below will correctly print the names of the Person ob

ID: 3840438 • Letter: W

Question

Which of the code segments below will correctly print the names of the Person objects in people? Why? I. for (Iterator it = people Iterator (; it Next():] {Person temp = it.next[]; System out.println (temp.getName()];) II. for (Iterator it = people get[0]; hasNext[];) {Person temp=it.next []; System.out.println (temp.getName()]; III. Iterator it = people iterator(); While (it.hasNext()}{Person temp = it.next(); System.out println (temp.getName();} a. I only b. II only c. III only d. I and III only e. I, II, and III The following segment of code is executed. people add (new Person ("Anna", 23)); people.add (new Person ("Thomas', 17)); people.add(new Person ("Lara", 19)); people.add (new.Person ("David", 34)); people.add (new Person ("Karen", 22)); Iterator it=people.iterator (); it.next(); it.next(); Person temp= it.next(); it.remove (); temp = it.next(); System.out.println (temp.getName()]; What will be printed to the screen? Why? a. Anna b. Thomas c. Lara d. David e. Karen

Explanation / Answer

18 ) I and III only
Reason : I : Iterator is declared with person.iterator()
Checks if nexts elements are present using it.hasNext()
Increments next using it.next();

Same with III as well

For II : we declare iterator as person.get(0) it doesn not return an itertor hence false


19) (c) Lara

Reason we do it.next() thrice and it points to David which is removed hence it now hold Lara



Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote