• 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
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

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?


 
Bartender
Posts: 5897
57
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.
 
Sheriff
Posts: 13510
223
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: 1945
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?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!