0

Can I have array with user's inputs?

24th Aug 2016, 3:52 PM
Fanda Zajíc
5 ответов
+ 4
integer array 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++){//for reading array arr[i]=s.nextInt(); } for(int i: arr){ //for printing array System.out.println(i); } } }
24th Aug 2016, 5:43 PM
Agha Asad Khan
Agha Asad Khan - avatar
+ 1
yes
24th Aug 2016, 3:54 PM
Ayush chadha
Ayush chadha - avatar
0
yes
24th Aug 2016, 5:11 PM
Aayushi Gupta
Aayushi Gupta - avatar
0
yes it is possible. you can do it with the help of 'for' loop .
24th Aug 2016, 5:16 PM
Agha Asad Khan
Agha Asad Khan - avatar
0
can you tell mr how? i tried many syntaxes (for loop too) but nothing worked..
24th Aug 2016, 5:30 PM
Fanda Zajíc