GeeCON Prague 2014*
The moose likes I/O and Streams and the fly likes Reading Through System.in Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Reading Through System.in" Watch "Reading Through System.in" New topic
Author

Reading Through System.in

Satyajit Bhadange
Ranch Hand

Joined: May 13, 2010
Posts: 104


Using above code i am trying to read following input

1 10
100 200
201 210
900 1000

but it not reading last line of input.what is wrong with my code ?


Thanks
user101
Problems And Solutions - Algorithms
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39062
    
  23
I tried it and found no errors. Please explain more.
Satyajit Bhadange
Ranch Hand

Joined: May 13, 2010
Posts: 104
i am running code on eclipse.
I am copying input and pasting it into eclipse console.
while reading last line,it goes into infinte loop.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39062
    
  23
Does it really go into an infinite loop?

You do realise you have to give it a null line, which you do by entering the end-of-file character? On Windows® try ctrl-Z, on *nix try ctrl-D. If you don't give it an end-of-file, it always assumes it is at the start of a new line.
Satyajit Bhadange
Ranch Hand

Joined: May 13, 2010
Posts: 104
yes it doesn't go into infinite loop ,it just waits for user input .

and secondly ,what condition should go in while statement so that loop terminates even if there is no null given. ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39062
    
  23
Try changing the != null test to the isEmpty() ,method. Remember the bang operator ! before (s. Using String#isEmpty() will stop if you use the enter key twice.

Beware: it only works in Java6+. Otherwise you can try .length() > 0
Satyajit Bhadange
Ranch Hand

Joined: May 13, 2010
Posts: 104
Thank you
 
GeeCON Prague 2014
 
subject: Reading Through System.in