Accept n numbers from the keyboard and print it in java

Write a java program to accept n numbers from the keyboard and print it.

package array;

import java.util.*;
public class array1 
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        int size;
        System.out.println("enter the array size:");
        size=s.nextInt();
        int c[]=new int[size];
        int i;
        System.out.println("enter the array elements:");
        for(i=0;i<size;i++)
        {
            c[i]=s.nextInt();
        }
        for(i=0;i<size;i++)
        {
            System.out.println("elements are::"+c[i]);
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *