+ 2
Why Scanner followed by a bufferedReader gives a Null pointer Exception ?
int n = scanner.nextInt(); scanner.nextLine() String[] unsorted = new String[n]; for (int i = 0; i < n; i++) { String unsortedItem = br.readLine(); unsorted[i] = unsortedItem; } int n =Integer.parseInt(br readLine()); String[] unsorted = new String[n]; for (int i = 0; i < n; i++) { String unsortedItem = br.readLine(); unsorted[i] = unsortedItem; } Just changing the 1st section of code with 2nd section solves the Exception in my Code , why is this happening ?? You can check the code ,by giving input : Length of Array , followed by its elements Eg - 4 1 2 3 4 https://code.sololearn.com/c3R2631V6N3f/?ref=app
3 Respuestas
+ 5
Never done it, but this might help.
https://stackoverflow.com/q/7635917/10057029
+ 1
It didn't helped ,but I get to know something new.
0
LukArToDo or Danijel Ivanović , Can you explain this ?