• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying an integer in a string

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic