• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

A code i cant make work

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"dada daadasd", did you check your private messages ?
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"dada daadasd",
Please read our Naming Policy carefully and change your name accordingly (obviously fake names are not allowed).
reply
    Bookmark Topic Watch Topic
  • New Topic