File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes A code i cant make work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A code i cant make work" Watch "A code i cant make work" New topic
Author

A code i cant make work

Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128
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

Joined: Jun 01, 2010
Posts: 618
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

Joined: Feb 23, 2007
Posts: 1561
cross-posted in java-forums: link to Java-Forums thread

OP, please see link to FAQ in your other thread.
Brad Dwan
Ranch Hand

Joined: Apr 22, 2010
Posts: 62
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.

-Nev
"It's about choosing your battles, not fighting somebody else's war"
Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

"dada daadasd", did you check your private messages ?


[My Blog]
All roads lead to JavaRanch
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
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?


Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Jun 21, 2010
Posts: 128
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

"dada daadasd",
Please read our Naming Policy carefully and change your name accordingly (obviously fake names are not allowed).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A code i cant make work