73.8k views
5 votes
What is the output of the following code? public class Test { public static void main(String[] args) { int list[] = {1, 2, 3, 4, 5, 6}; for (int i = 1; i < list.length; i++) list[i] = list[i - 1]; for (int i = 0; i < list.length; i++) System.out.print(list[i] + " "); } }

User Kam
by
5.3k points

1 Answer

4 votes

Answer:

1 1 1 1 1 1

Step-by-step explanation:

You copy the first location to the second, and then the second to the third, and so on. Effectively the value of the first location (1) is copied to all locations.

User Naveen DA
by
4.9k points