array

Sparsh asked 2 years ago

Wap to input 10 number in an array

1 Answers
AMITABHSIR Staff answered 2 years ago

import java.util.*;
public class method1
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int n[]=new int[5]; // create an array n of size 5
for(int i=0;i<5;i++)
{
System.out.print(“Enter a number : “);
n[i]=sc.nextInt(); //accept number and store it in array
}

// display the array content
for(int i=0;i<5;i++)
{
System.out.println(“The number is : ” + n[i]);
}
}
}