• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Jeffrey Gutierrez
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.

 
Tony Docherty
Bartender
Posts: 3271
82
  • 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
 
Tim Cooke
Marshal
Posts: 4039
239
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!

 
Liutauras Vilda
Sheriff
Posts: 4916
334
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.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • 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: 4039
239
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: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We all say silly things from time to time. Think nothing of it.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!