Java Program Array Read Example

This java code will read and display elements of an array.
import java.io.*;
class Arr2
{
                public static void main(String args[])throws IOException
                {
                                DataInputStream dis=new DataInputStream(System.in);
                                int a[]=new int[5];
                                int i;
                                for(i=0;i
                                {
                                                System.out.print(“Enter the value :”);
                                                a[i]=Integer.parseInt(dis.readLine());
                                }
                                for(i=0;i
                                {
                                                System.out.println(a[i]);
                                }
                }
}

Add Comment