I was trying to do this :
int n = myScanner.nextInt();
for(int i=0;i<n;i++){
String str = myScanner.nextLine();
.
.
.
}
when i compiled it shows some errors java.util.Scanner.nextInt(Scanner.java:2117). initially i thought it is a problem of nextLine() so i used next() . then i found out if i add myScanner.nextLine() after taking input in n i.e
int n = myScanner.nextInt();
myScanner.nextLine();
Then it worked fine. I want to know why this happened?
NumberFormatExceptionwill be thrown only if it cannot be parsed. But aNumberFormatExcetionis an unchecked (extending RuntimeException) exception, so you don't have to explicitely write throws or handle it (though it will be thrown up if you dont). Hope that's clear.