How to take input from user side for array using scanner class? Any other method will also be appreciated. for example, if we need to create an array and then taking input from user side. Thank you!!
SureshBonam
Check the following code...It is for reading 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);
}
}
}
来源:https://stackoverflow.com/questions/25444786/taking-user-input-array-in-java-using-scanner-class