This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Guessing game

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are multiple lines displaying for the output. How do I change that to only 1 line for the user to enter while displaying the stuff in the if-else if statement?

The program should also look like :
Enter a number between 1 and 20: 14
Secret number:20
Player's number:14
Better look next time
or
Enter a number between 1 and 20: 2
Secret number:2
Player's number:2
You won!

Is the code looking right?


 
Saloon Keeper
Posts: 6213
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

lisa jano wrote:Why are multiple lines displaying for the output. How do I change that to only 1 line for the user to enter while displaying the stuff in the if-else if statement?

A println() call always ends with the outputting of a new-line character. If you don't want the new-line then use print(). If this doesn't answer your question then you need to restate your issue because it is a bit unclear.
 
Marshal
Posts: 14018
233
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, your code is incorrect. What do you think happens when the player guesses correctly? Follow the logic in your program to see if that's what happens.

Tip: Format your code better. See Java code conventions. The way you indented your code is inconsistent and confusing.
 
Rancher
Posts: 1992
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you actually need so many if else ifs?
 
We don't have time to be charming! Quick, read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!