222k views
6 votes
Assume that numList has been initialized with the following Integer objects: [0, 1, 2, 3, 4]. What is the value of numList after mystery(5) executes

1 Answer

5 votes

Answer:

The answer is "[0, 1, 2, 3, 4]"

Step-by-step explanation:

Following are the code to this question:

private List<Integer> numList;//declaring a list numList

public void mystery(int x)//defining a method mystery that take an integer parameter

{

for (int i = 0; i < x; i++)//defining for loop to remove and add value in numList

{

Integer obj = numList.remove(0);//removing Number from numList

numList.add(obj);//add Number in numList

}

}

In the above-given code, a numList is declared and defined as a method mystery that holds an integer variable "x" in its parameter, inside the loop method is defined that removes and adds value in numList. OR We may say that each value throughout this process is deleted and inserted at the ends of a list one by one, so the return and declaring list are the same.

User Ssasa
by
3.3k points