String longestname;

longestname=(lengthofname1>lengthofname2)?name1:name2;
longestname=(longestname>lengthofname3)?longestname:name3;

System.out.println(longestname + " has the longest first name!");

Hope I helped.

Regards,
Manu.


On Fri, Sep 19, 2008 at 3:14 PM, Rene Erwee <[EMAIL PROTECTED]> wrote:

>  Hi all
>
>
>
> Thank you David for your good explanation of String Arrays which finally
> enabled me to finish the homework.  However, I am wondering if there is a
> more condensed version to find and print the longest name.  I can imagine
> If-else-else if statements will not work too well when one has a whole lot
> of names to compare.
>
>
>
>         // Print the longest name
>
>             if((lengthOfFirstNameOfPerson1>=lengthOfFirstNameOfPerson2) &&
>
>         (lengthOfFirstNameOfPerson1>=lengthOfFirstNameOfPerson3)){
>
>             System.out.println(firstNameOfPerson1[0] + " has the longest
> first name");
>
>         }
>
>         else if ((lengthOfFirstNameOfPerson2>=lengthOfFirstNameOfPerson1)
> &&
>
>         (lengthOfFirstNameOfPerson2>=lengthOfFirstNameOfPerson3)){
>
>             System.out.println(firstNameOfPerson2[0] + " has the longest
> first name");
>
>         }
>
>         else {
>
>             System.out.println(firstNameOfPerson3[0] + " has the longest
> first name");
>
>         }
>
>     }
>
>     }
>
>
>
> Thanks
>
> * *
>
> *Rene Erwee*
>
> >
>


-- 
This email may contain confidential and privileged proprietary material for
the sole use of the intended recipient. Any review, use, or distribution or
disclosure by others is strictly prohibited. If you are not the intended
recipient, or authorized to receive the information from the recipient,
please contact the sender by reply email and delete all copies of this
message.

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to