• 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Displaying an integer in a string  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hello again. I have a minor question. I have a integer variable "guessNumber". I'm using the provided JOptionPane... in order to have the user tell whether guessNumber is higher, lower, or exactly the number they were thinking of. Only problem is, I can't seem to display the variable when I run the program. It just shows the text within the quotations. Any help?
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Michael Roslansky wrote:Hello again. I have a minor question. I have a integer variable "guessNumber". I'm using the provided JOptionPane... in order to have the user tell whether guessNumber is higher, lower, or exactly the number they were thinking of. Only problem is, I can't seem to display the variable when I run the program. It just shows the text within the quotations. Any help?


Well, I'm certainly no GUI expert; but what you've written doesn't jive with what I understand about JOptionPane. My suggestion would be to actually make the value part of the message; and the easiest way to do that is probably with String.format(). After that, I suspect you're also going to need a way of providing the user choices of greater/less/equal, but I'm afraid I'm not the best to advise you on how to do that.

Winston
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using a comma between your String and the int variable sends two seperate arguments (a String and an int) to the showInputMessage method. It sounds like you want to just send one concatenated String. If you replace the comma with a + that should do what you want.

I'm assuming you're expecting the user to type in either "higher", "lower", or "exactly" which is easier to code for as a beginner than creating a button for each option, even though it is a little less user friendly.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!