how to input an array code example
Example 1: take array as input in c
int size=5;
int array[size];
for(i=0;i<size;i++){
scanf("%d",&array[i]);
}
Example 2: input array through scanner in java
public static void main (String[] args)
{
Scanner input = new Scanner(System.in);
double[] numbers = new double[5];
for (int i = 0; i < numbers.length; i++)
{
System.out.println("Please enter number");
numbers[i] = input.nextDouble();
}
}
Example 3: how to get an array as input in java
public class TakingInput {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("enter number of elements");
int n=s.nextInt();
int arr[]=new int[n];
System.out.println("enter elements");
for(int i=0;i<n;i++){
arr[i]=s.nextInt();
}
for(int i: arr){
System.out.println(i);
}
}
}