+ 1

Help me solve the code guys...never dealt with an exception before...

https://code.sololearn.com/cJ7oce2oaSpp/?ref=app

3rd Jun 2018, 4:08 PM
Coding Niffler
Coding Niffler - avatar
4 Réponses
+ 1
I got a NumberFormatException which means the program tried to turn something into a number that couldn't be done e.g. trying to convert "Bob" into a number
3rd Jun 2018, 4:15 PM
Dan Walker
Dan Walker - avatar
+ 1
The second call to readLine() on the BufferedReader returned null, because you've already taken the first number (this is assuming you input one number) so parseInt will fail to work and throw the exception. You could verify that you have enough inputs before making the call or use a try-catch block to handle the exception. You should really verify the inputs first, and not use a catch to control the flow of the program
3rd Jun 2018, 4:22 PM
Dan Walker
Dan Walker - avatar
0
so how do I solve it?
3rd Jun 2018, 4:16 PM
Coding Niffler
Coding Niffler - avatar
0
shall I create a subclass so that the second call to readLine() does not return null and fail? I don't know any other exception other than catch which can control the flow of the program.. how to verify inputs?
3rd Jun 2018, 4:25 PM
Coding Niffler
Coding Niffler - avatar