Display numbers 1 to 10 using array

PROGRAM:

public class MainClass

{ public static void main(String[] args) throws IOException { int[] list = new int[10]; // Fill the array for (int i = 0; i < list.length; i++) list[i] = i+1; // Display the contents of the array for (int i = 0; i < list.length; i++) System.out.println(list[i]); } OUTPUT:
1
2
3
4
5
6
7
8
9
10

Comments