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

Guessing game  RSS feed

 
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: 5839
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor 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: 13458
222
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • 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: 1944
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you actually need so many if else ifs?
 
Hey! Wanna see my flashlight? It looks like this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!