Originally posted by Campbell Ritchie:
Why are you putting a try-catch around the code in inarr which doesn't declare an exception, and not catching the IOException from the BufferedReader? And why are you not closing the BufferedReader?
What are you entering to get the NumberFormatException? You must enter something which is a real number, then you won't get the NumberFormatException, so you can go on and deal with the NullPointerException which you will get in the next stage![]()
By the way: there is no such thing as a two dimensional array in Java. What you have set up is an array of arrays.
And if you are using a BufferedReader, you can only enter one number on each line. A Scanner would have been easier to use.
You can write 2 3 4 5 6 (not at the command line) and pass that line to a Scanner
System.in and System.out and System.err probably don't need to be closed. All the other Streams do, not those three. You probably mean sc.close();
You can have a for loop to count how many values you want from the standard input
The only way to get -1 from a Scanner reading from System.in is to write -1. It doesn't have a default to -1 for end of stream.
You will occasionally have to use the nextLine() method to move onto a new line, and discard the input.