Java


Java Tutorial


Admission Enquiry Form

  

Integer Array Input Using loop




Code for Integer Array Input from User Using Loop:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class UserInput
{
public static void main(String[] args) throws IOException
{
int[] arr=new int[5];
Scanner scr=new Scanner(System.in);
int i;
for(i=0;i<arr.length;i++)
{
System.out.println("Enter number ");
arr[i] = scr.nextInt();
}

        System.out.println("The elements of an array are: ");
for(i=0;i<arr.length;i++)
{
System.out.print(arr[i]+" ");
}
}
}

Output

Enter number
10
Enter number
20
Enter number
30
Enter number
40
Enter number
50
The elements of an array are:
10 20 30 40 50