Consider the following method: public static void whoAmI(ArrayList list) { for (int i = 0; i < list.size(); i++) { int element = list.get(i); list.remove(i); list.add(0, element + 1); System.out.println(list); }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 18RQ
icon
Related questions
Question

Java

Consider the following method:
public static void whoAmI(ArrayList<Integer> list) {
for (int i = 0; i < list.size(); i++) {
int element =
list.get(i);
list.remove (i);
list.add(0, element + 1);
System.out.println(list);
}
What is the output produced by the method when the Arraylist
[-1,3,28,17,9,33] is given as a parameter?
O [34, 10, 18, 29, 4, 0]
O [33,9,17,28,3,-1]
O -1,-1,-1,-1,-1.-1]
O -1,3,,28,17,9,33]
Transcribed Image Text:Consider the following method: public static void whoAmI(ArrayList<Integer> list) { for (int i = 0; i < list.size(); i++) { int element = list.get(i); list.remove (i); list.add(0, element + 1); System.out.println(list); } What is the output produced by the method when the Arraylist [-1,3,28,17,9,33] is given as a parameter? O [34, 10, 18, 29, 4, 0] O [33,9,17,28,3,-1] O -1,-1,-1,-1,-1.-1] O -1,3,,28,17,9,33]
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Introduction to computer system
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT