Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying an integer in a string

 
Michael Roslansky
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?
 
Winston Gutkowski
Bartender
Pie
Posts: 10083
55
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
 
Chip Furstenau
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic