Win a copy of Design for the Mind this week in the Design forum!
    Bookmark Topic Watch Topic
  • New Topic

trouble inhasNext

 
hayri hocaoglu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
why ı can exit the loop with pressing enter
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
hmm ı understand. can you say how ı can do that exit to loop when ı press enter.
 
Tony Docherty
Bartender
Posts: 2952
59
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't delete code/text in an earlier post after getting an answer. It makes the thread unreadable for others.
 
Henry Wong
author
Marshal
Pie
Posts: 20996
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
Paul Clapham
Sheriff
Pie
Posts: 20955
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Sheriff
Pie
Posts: 20955
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Marshal
Pie
Posts: 20996
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
    Bookmark Topic Watch Topic
  • New Topic