• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A code i cant make work

 
Dmitri Makovetskiy
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i succeeded in letting the user put any 10 numbers he wants, but i cant make the application choose which number is the highest and list it...



How can i make the program choose the highest input and display it?
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try defining a variable called maxInt and use it to keep track of the biggest number that the user entered. Then print it out at the end.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cross-posted in java-forums: link to Java-Forums thread

OP, please see link to FAQ in your other thread.
 
Brad Dwan
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As mentioned above, you could simply add another variable and let it contain the max value.

eg.


Thats just an example of how to achieve it, but there are other ways that are more refined.
 
Dmitri Makovetskiy
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brad Dwan wrote:As mentioned above, you could simply add another variable and let it contain the max value.

eg.


Thats just an example of how to achieve it, but there are other ways that are more refined.



we cant use if variable, we can use trilinear operator.

could you transfer this to a trilinear expression: (i added a max=0 variable above the loop method)
if(n1 > max) {max = n1;}


Edit:

i actually got it..here is the correct expression:

max=(n1>max)?n1:max;

thanks. problem resolved
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"dada daadasd", did you check your private messages ?
 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a crossposting from you?
http://answers.yahoo.com/question/index?qid=20100621233127AAA7JfB

Probably you should read about the ternary operator first:
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op2.html

Then you should be able to transfer a simple if / else by yourself ... don't you think?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter Taucher wrote:Is this a crossposting from you?
http://answers.yahoo.com/question/index?qid=20100621233127AAA7JfB

If it is, you should BeForthrightWhenCrossPostingToOtherSites.
 
Dmitri Makovetskiy
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter Taucher wrote:Is this a crossposting from you?
http://answers.yahoo.com/question/index?qid=20100621233127AAA7JfB

Probably you should read about the ternary operator first:
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op2.html

Then you should be able to transfer a simple if / else by yourself ... don't you think?


yeah, i just did and yes. i did post a question at yahhoo..

i wouldnt have thought about using a second variable, cause in class we learnt to use only one variable..

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"dada daadasd",
Please read our Naming Policy carefully and change your name accordingly (obviously fake names are not allowed).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic