This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing out inputted integers in order from least to greatest.  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm back, expect me here very often! I think I got the right idea with this program, but the problem is, when I run it in netbeans it doesn't display the numbers like 3,5,6 but rather displays the variable letters I assigned to them, i.e. a , c , b.

 
Bartender
Posts: 3306
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println will output whatever is in the String you pass to it and you are passing the String "c + a + b". If you want to output the values of the variables a,b & c you need to concatenate a String from the variables values and the String parts.

For example:
might output:
My age is 23 and I was born in July
 
Marshal
Posts: 4349
280
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So take Tony's advice and apply it to your own program. Try the following statements:

Perhaps you want to put a space between the numbers:
 
Jeffrey Gutierrez
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, here is the fixed code, hope it inspires someone!

 
Marshal
Posts: 5589
383
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeffrey Gutierrez wrote:here is the fixed code, hope it inspires someone!


You're missing quite few curly braces around "if's" and "else if's". What Java convention says?

Method "getOrder" doesn't return any value, so better would be name it as "printOrder" or something.
Normally the methods which starts with "getSomething" we call "getters", it means it returns something back - it is not a case in your method.
 
Marshal
Posts: 58321
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Cooke wrote: . . .
. . .

I presume 356 is what you hope it will print, not what it will actually print Now, that will print 356. I shall leave it to readers to work out why.
 
Tim Cooke
Marshal
Posts: 4349
280
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Tim Cooke wrote: . . .
. . .

I presume 356 is what you hope it will print, not what it will actually print


Quite right you are Campbell. What a dummy I can be sometimes.
 
Campbell Ritchie
Marshal
Posts: 58321
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We all say silly things from time to time. Think nothing of it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!