Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes trouble inhasNext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

trouble inhasNext

hayri hocaoglu
Greenhorn

Joined: Dec 19, 2012
Posts: 3
why ı can exit the loop with pressing enter
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39053
    
  23
Welcome to the Ranch

Although you correctly used the code tags, that code is surprisingly difficult to read. And I am not quite sure what your question means. I think you need to go back a stage. There is a bit of hardware getting between you and the solution. It is a black wire between the wall and your computer. Remove that, then try with a sheet of paper. Read carefully what Scanner#hasNext() does, and see if you can work out any circumstances in which it might return false when you are using the keyboard. You appear to be using the input as an int, so why don’t you look for a method which keeps returning true until you don’t have an int? Or what about a while loop instead of the do looP? Somebody else had similar problems, so you can see you can terminate your loop by writing stop.
hayri hocaoglu
Greenhorn

Joined: Dec 19, 2012
Posts: 3
hmm ı understand. can you say how ı can do that exit to loop when ı press enter.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2301
    
  49
Please don't delete code/text in an earlier post after getting an answer. It makes the thread unreadable for others.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

hayri hocaoglu wrote:why ı can exit the loop with pressing enter


Well... with the original question (and all content) deleted, I am assuming that this followup question is rhetorical?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Original post recovered from Google cache (with code tags added):

I want to exit when ı press enter but this hasnext doesnt work what can ı do ?
>
hayri hocaoglu
Greenhorn

Joined: Dec 19, 2012
Posts: 3
Paul Clapham wrote:Original post recovered from Google cache (with code tags added):

I want to exit when ı press enter but this hasnext doesnt work what can ı do ?
>

ı want to remove this question because of wrong question
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

hayri hocaoglu wrote:ı want to remove this question because of wrong question


It's very confusing when somebody posts a question, and then other people talk about it, and then the original poster deletes the question. It just makes the thread look incoherent. So we don't really like it when that happens.

But if the question was wrong, then no problem... just say so, ask the right question, and the thread can continue.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

hayri hocaoglu wrote:
ı want to remove this question because of wrong question


Maybe it would be a good idea to start a new topic with the right question -- this topic seems to be a mess at this point.

Henry
 
GeeCON Prague 2014
 
subject: trouble inhasNext