Hi,

Apologies for posting the whole network solutions for discussion, I am not
aware that this is not permited.  Thanks for the tips, this logic is much
better that my originial method.

Regards
KC
On Thu, Apr 8, 2010 at 5:49 PM, Michèle Garoche <[email protected]> wrote:

>
>  Le 8 avr. 10 à 03:50, Kim Ching Koh a écrit :
>
>  Hi,
>
> Thanks.. I managed to write the code to compare three persons, below is my
> code, but I am just thinking how to use a two dimensional array for the
> nameArrayForPerson, instead of three arrays.   The key here is still to let
> .split() define the array size for the nameArray.  Any tips?
>
> Regards
> KC
>
>     public static void main(String[] args) {
>         // TODO code application logic here
>         String fullName[] = new String[3];
>         String longestFirstName = "";
>         for (int i = 0; i < fullName.length; i++) {
>             fullName[i] = JOptionPane.showInputDialog("Please enter a
> family member's name " + i + 1);
>             System.out.println(fullName[i]);
>         }
>
> ...deleted to not show your whole homework solution
>
>     }
>
>
> Instead of working on retrieving the longest first name out side of the for
> loop, you may initialize before the for loop a String firstName to an empty
> string and then use the split method on the fullName[i] you read inside the
> for loop. Then you compare the longestFirstName with the firstName, always
> inside the for loop, and change the former to the latter if needed. You also
> need an index (initialized before the loop, and changed inside the loop) to
> retrieve after the loop the index which corresponds to the longest first
> name.
>
> There may be other solutions.
>
> Michèle
>
>
>
>
>
>
> On Wed, Apr 7, 2010 at 10:16 PM, miga <[email protected]> wrote:
>
>>
>>
>> On Apr 7, 2:51 pm, kc <[email protected]> wrote:
>> > Hi,
>> >
>> > Is there a typo error here?  To compare Two or Three family members?
>> No there is no error. You compare the first name of three members of
>> the same family. It may happen that two member of this family have
>> first name which length is the same and both have the longest name in
>> the family, like Pat, John and Duke, John and Dude have both the
>> longest name, 4 characters for both. The tie refers to this, so if it
>> is the case, you display the one you want, either John or Duke.
>>
>> Hope it helps,
>> Michèle
>>
>> >
>> > Ask the English version of the full names (first-name last-name) of
>> > three of your family members using showInputDialog() method of the
>> > JOptionPane class.
>> > Display the name of the family member who has the longest first name
>> > (not the longest of the  total name) as following.  (If there is a
>> > tie, just display one of the two.)
>> >
>> > Regards
>> > KC
>>
>> --
>> To post to this group, send email to
>> [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]<javaprogrammingwithpassion%[email protected]>
>> For more options, visit this group at
>> http://groups.google.com/group/javaprogrammingwithpassion?hl=en
>>
>> To unsubscribe, reply using "remove me" as the subject.
>>
>
>
>

-- 
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