I'm trying to get n lines of input (Strings) from the user
- The n is set first
- I initialize an array of Strings to save the input and for loop to save them.
The problem is that it always falls short meaning
- if n=1 the program is terminated
- if n=2 it takes only 1 input
- if n=3 it takes only 2 inputs and so on ......
What is wrong ?
Scanner sc = new Scanner(System.in);
//how many lines should be taken
int lines = sc.nextInt();
// initialize input array
String[] longWords = new String[lines] ;
//set the input from the user into the array
for (int i = 0; i < longWords.length; i++) {
longWords[i] = sc.nextLine() ;
}