aspose file tools*
The moose likes Beginning Java and the fly likes Displaying an integer in a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Displaying an integer in a string" Watch "Displaying an integer in a string" New topic
Author

Displaying an integer in a string

Michael Roslansky
Greenhorn

Joined: Mar 12, 2013
Posts: 10


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

Joined: Mar 17, 2011
Posts: 7081
    
  16

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

Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
Chip Furstenau
Greenhorn

Joined: Mar 29, 2013
Posts: 4
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying an integer in a string
 
Similar Threads
Generic methods and wildcards
what is the mistake inthis simple code
Random numbers
String as key to look up an Integer
Passing Long variable as an argument and returning long?