Need Help Using Scanner

Write here if you have problems with your Java source code

Moderator: Board moderators

Post Reply
New poster
Posts: 2
Joined: Sat Sep 22, 2007 11:48 pm

Need Help Using Scanner

Post by Coalwater »

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( ?

Thank you
New poster
Posts: 2
Joined: Wed Aug 02, 2006 1:08 am
Location: Cairo

Re: Need Help Using Scanner

Post by bekerpico »

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
Experienced poster
Posts: 158
Joined: Sun Feb 04, 2007 7:45 pm
Location: Medellin, Colombia

Re: Need Help Using Scanner

Post by andmej »

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?
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland

Re: Need Help Using Scanner

Post by mf »

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:

Code: Select all

java Main <input_file >output_file
(provided that you've called the main class just "Main")

This works under every OS I know.
Post Reply

Return to “Java”