0
How can we take inputs of array from the user?
can somebody tell me plz...
3 Answers
+ 2
int[] a = new int[5];
Scanner s1 = new Scanner(System.in);
for(int i=0;i<5;i++)
a[i]=s1.nextInt();
0
use a for loop. each value of the loop control variable will serve as the array index. and store the input into that array index, as you do for normal inputs. the diff is just that in normal cases you would use a variable to store the data and here each position in the array serves as the variable.
0
int[] a = new int[5];
Scanner s1 = new Scanner(System.in);
for(int i=0;i<5;i++)
a[i]=s1.nextInt();