• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting Started  RSS feed

 
Keanan Hendricks
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody, would just like to say that I feel this is an amazing community.
I really enjoy the fact that you are all so helpful and informative, I have recently purchased the Head First Java Book and just complete the fist 3 Chapters.

I decided to create a short little class / app (not sure what to call it)
and cant figure out why the last Object is not called through with the random number.

Really would appreciate your input and any assistance.
Thank you


 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Keanan and welcome to the JavaRanch.

Thank you for your kind words. Please UseCodeTags when posting code. It will highlight your code and make it much easier to read. It probably will also increase the number of people helping you. I'll add them for you since you are new so that you can see the difference.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The last isn't being called because the Math.random() * 3 only returns values in the range of 0-2.

Why are you using while with break when you only want it to be executed once?
 
Keanan Hendricks
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lol The reason is last time I removed the break it kept running and running, I try playing with the while statement but cant seem to get it right.
Thank you for the quick reply
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason it keeps running and running without the break statement is because of the fact that x is not getting incremented.
 
Keanan Hendricks
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would be the best way to have the while statement complete without the use of the break?
Really appreciate your input.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the while statement there is a condition: while(condition) {/*code */}. When that condition returns false the while loop stops. So what could you do to make that condition return false after a couple of rounds?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!