I have the following input in 3 lines:
line 1: consists of positive int m and n separated by white space
line 2: list of m int separated by white space
line 3 and beyond: list of n words separated by white space or newline character
I am unable to read beyond m and n into my code
My Code:
Scanner input = new Scanner(System.in);
m = input.nextInt();
n = input.nextInt();
int[] lines = new int[m];
String[] words = new String[n];
input.nextLine();
for (int i = 0; i < m; i++) {
lines[i] = input.nextInt();
}
for (int i = 0; i < n; i++) {
words[i] = input.next();
}
How to read the line and words into the arrays after i call the first nextLine(), and try to read the numbers, i get a nullpointerexception