The following code shows how to Initialise and Display Array in Java. Here the array elements are provided by the user using command line arguments.

Since, we use command line arguments to initialise the array, the elements need to be converted into integers. This is because command line arguments create array of strings.

public class Main
{
	public static void main(String[] args) {
	    System.out.println("Array created using command line arguments...");
	    int[] myarray=new int[args.length];
	    for(int i=0;i<args.length;i++)
	    {
	        myarray[i]=Integer.parseInt(args[i]);
	    }
	    for(int i=0;i<myarray.length;i++)
	        System.out.println(myarray[i]);
		System.out.println();
	}
}

Output

Array created using command line arguments…
12
4
8
98
44
563
78
16
9
94
3
85


Further Reading

Java Practice Exercise

programmingempire