0

How can we take inputs of array from the user?

can somebody tell me plz...

22nd Mar 2016, 7:05 PM
Ram Dafe
Ram Dafe - avatar
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();
25th Jun 2016, 5:11 PM
gandhiyash
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.
25th Mar 2016, 2:39 PM
Tanuj Saraf
Tanuj Saraf - avatar
0
int[] a = new int[5]; Scanner s1 = new Scanner(System.in); for(int i=0;i<5;i++) a[i]=s1.nextInt();
25th Jun 2016, 5:11 PM
gandhiyash