Tuesday, July 14, 2009

Java Conditional Operator Problem PLS help?

Hi I have a problem that I cant solve. We have a school exercise in Java abt conditional operator (?:) We were asked to code the following:





a=1


b=2


c=3


highest number is = 3





I was able to code this correctly after a LONG time, and with some help. Now I am trying to do more practice and is trying to code the following, and it seems like I am stuck in deep mud again. Pls help me. I am trying to code:





a=1


b=2


c=3


d=4


highest number is = 4





pls help me

Java Conditional Operator Problem PLS help?
just remember, all the ?: operator is a short hand for if-then-else





or in this case multiple if then elseif's(don't know the exact java syntax)





but would look something like


(a%26gt;b)?((a%26gt;c)?((a%26gt;d)?print a : print d):((c%26gt;d)? print c : print d)...





if you got the above part all this last part is one more check at each level of the if then elseif all you doing is writing as you comparing a to the other 3 first... if true in all cases a is highest if false in last case d is highest... if false before then you need to check that variable with the rest down the line gave you if c%26gt;a case all you need to do is finish with if b%26gt;a using paranthesis and even adding lines might help for readability


No comments:

Post a Comment