This is the code. I tried to solve it, but I can\'t understand how its output is 111111?
public class Test {
public static void main(String[] args) {
for (int i = 1; i < list.length; i++)
list[i] = list[i - 1];
This part of your code causes value of all items in list is 1.
When i = 1, list[1] = list[0] = 1;
when i = 2, list[2] = list[1] = 1; //not 2 because it is already overrided when i = 1.
.... to last one.
P/S: Try to understand step by step in your code before asking question.