I’m trying to get a set of string statements (which can include spaces) into a string array. The number of statements will be decided by the input of the user.
So I thought of looping the input.nextline(); function.
But I think as soon as enter is hit it is taken as \n to all the loops..
Is there any better way to do this?
Scanner input = new Scanner(System.in);
System.out.println("How many Inputs??");
numOfInputs = input.nextInt();
String[] dataStore = new String[numOfInputs];
System.out.println("Input Strings");
for(i=0;i<numOfInputs;i++){
System.out.print("Input "+(i+1)+ " = ");
dataStore[i] = input.next();
}
Try this . I corrected the mistakes.