Hi Srini,
I believe the first two lines split the names by a space and place
them in separate array elements.
> String[] nameArrayForPerson1 = person1NameInstance.split(" ");
> String[] nameArrayForPerson2 = person2NameInstance.split(" ");
For instance, if the names were "Jane Does" and "William Henry Jr",
"Jane Doe" would be placed in an array with two elements "Jane" and
"Doe" and "William Henry Jr" would be placed in an array with three
elements "WillIam", "Henry" and "Jr".
The next two lines of code compare the first element value of each
array, in this case it should be the first array element value for
each array should be the first name. I believe the array is zero
based meaning the first element is accessed by zero, the second
element is accessed by the value 1 and so on. The length of the values
in the first element of each array are stored to an integer variable.
Aloha,
James
> int lengthOfFirstNameOfPerson1 = nameArrayForPerson1[0].length();
> int lengthOfFirstNameOfPerson2 = nameArrayForPerson2[0].length();
On Jan 22, 7:38 pm, Srini S <[email protected]> wrote:
> Hi,
>
> The homework is to accept three names (first and last) and find out
> the longer first name. Can someone explain me the following lines
> which is on the hint:
>
> // Get the first name from a name string using split() instance (non-
> static) method
> String[] nameArrayForPerson1 = person1NameInstance.split(" ");
> String[] nameArrayForPerson2 = person2NameInstance.split(" ");
>
> // Get the lengths of strings using length() instance (non-static)
> method
> int lengthOfFirstNameOfPerson1 = nameArrayForPerson1[0].length();
> int lengthOfFirstNameOfPerson2 = nameArrayForPerson2[0].length();
>
> Thanks,
> Srini.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---