Hm, check this out. It suggests that it might be due to program bugs which cause segmentation fault (unlikely here), or if input format is not correct. Quoting the key phrase-
Barring unlikely scenarios, the only possibilities for getting a nonzero exit code with that programme that I see are
1.division by zero, but that can't happen if the input conforms to the specifications
2.unexpected input format resulting in a NumberFormatException
Assuming @ssaxena32 's implementation and things are exactly same, and only difference is that he used C++ instead of JAVA, I advise you to try Buffered Reader and see if it still gives NZE error or not. If the issue resolves, then the problem is in input/testcases.
Check and get back to me in case issue doesn’t resolve.
There must be some mismatch in the input format of the testcases that is why a runtime error is produced in Java. C++ is efficiently able to handle them.
@sagar2009kumsr, your code is quite fine but there are issues with the test cases. This submission gives a runtime error and if you see this one you can understand that the runtime error you are getting is a NoSuchElementException (this gets WA because I suprressed that particular error), and another submission seems to indicate the the end-of-file is reached prematurely as it returns with a NZEC.
My best guess is that the test input is an incomplete file which is causing the error when you try to read beyond the end of the file, so it is not a fault of your code.