i have a problem with Scanner (java.util.Scanner)
its in using Scanner.hasNext() while reading from console
the problem is that the program never stops and i get time limit exceed
cant i use hasNext() when the Scanner is scanner(System.in) ?
Thank you
Need Help Using Scanner
Moderator: Board moderators
Re: Need Help Using Scanner
Yes , you can . but you can't test it in your compiler, because you have to make the input has an end and you can't do that while it's waiting input from keyboard while the automatic judge can do .
PicO's reply
Re: Need Help Using Scanner
Actually, if you are using Linux you can. Just press Ctrl + D at a console waiting for input and it will send the EOF signal to the process. If you are using Windows, download a Linux distro for free.
Runtime errors in Pascal are reported as Wrong Answers by the online judge. Be careful.
Are you dreaming right now?
http://www.dreamviews.com
Are you dreaming right now?
http://www.dreamviews.com
Re: Need Help Using Scanner
Windows's equivalent of Ctrl-D is Ctrl-Z.
Alternatively, you can force your program to read from a real file using redirection, just type in the command line:
(provided that you've called the main class just "Main")
This works under every OS I know.
Alternatively, you can force your program to read from a real file using redirection, just type in the command line:
Code: Select all
java Main <input_file >output_file
This works under every OS I know.