Page 1 of 1

What's the output of the following code segment? public static void main(String[] args) { LinkedList l

Posted: Thu May 05, 2022 1:34 pm
by answerhappygod
What's the output of the following code segment?

public static void main(String[] args) {
LinkedList<Integer> list = new
LinkedList<Integer>();
for (int i = 1; i <= 6; i++)
list.addLast(i);
while (list.size()>0) {
for (int i = 1; i < 4;
i++)

list.addLast(list.removeFirst());

System.out.println(list.removeFirst());
}
}