Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading Through System.in

 
Satyajit Bhadange
Ranch Hand
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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 ?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it and found no errors. Please explain more.
 
Satyajit Bhadange
Ranch Hand
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic