Name:_Abeban ott lew Quiz 02 C SCI 143 Arzaylist Mystery (10 Points) a) 3 Points
ID: 3914296 • Letter: N
Question
Name:_Abeban ott lew Quiz 02 C SCI 143 Arzaylist Mystery (10 Points) a) 3 Points b) 3 Points c) 4 Points d) Consider the following method: public gtatie void nystery (Arraylistcinteger list) ( for (int í 1; ? list.size ( ); ? += 2) if (list.get(i 1) list.get (i)) 1ist.remove (); list.add (0, 0) System.out.printin(list) Write the output produced by the method when passed each of the following ArrayLists: List Output a) [10, 20, 10, 5] b) te, 2, 9, 7, 1, 55] c) to, 16, 9, 1, 64, 25, 25, 14, 0] ??4Explanation / Answer
Answer:
1) [0, 10, 20, 10]
Explanation: We start with index 1 and see 10 >= 20 NO
We increment index from 1 to 3 and see 10>=5 , YES
so WE REMOVE 5 AND ADD 0 at index 0. Hence we get the list as 0, 10, 20 , 10 as 5 is removed
2) [0, 0, 8, 9, -1, 55]
Explanation: We start with index 1 and see 8 >= 2 Yes, we remove 2..
We increment index from 1 to 3 and see 9>=7 , YES, we remove 7
Hence we get 0, 0, 8, 9, -1, 55
3) [0, 0, 0, 0, 16, 9, 64, 25, 0]
Explanation: We start with index 1 and see 0 >= 16, NO
We increment index from 1 to 3 and see 9>=1 , YES, we remove 1
This way we continue at index 5, 7 etc
Hence we get [0, 0, 0, 0, 16, 9, 64, 25, 0]
Thanks, PLEASE UPVOTE if helpful
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.