ok the nameArrayForPerson1 and 2 split over the variable
person1NameInstance and person2NameInstance and both variable is not
declarates, the dialog in JOtionPane.showInputDialog must receive the
name in the variable person1NameInstance and person2NameInstance for
split the first Name of the person, look this:
//Declare the variable for maintain the names and the first name of
the person
String person1NameInstance,person2NameInstance;
String[] nameArrayForPerson1;
String[] nameArrayForPerson2;
// get the names
person1NameInstance = JOptionPane.showInputDialog("Please enter your
name");
person2NameInstance = JOptionPane.showInputDialog("Please enter your
name");
//split the name of the person
nameArrayForPerson1 = person1NameInstance.split(" ");
nameArrayForPerson2 = person2NameInstance.split(" ");
// Get the lengths of strings using length() instance (non-static)
method
int lengthOfFirstNameOfPerson1 = nameArrayForPerson1[0].length();
int lengthOfFirstNameOfPerson2 = nameArrayForPerson2[0].length();
// Compare the lengths of the first names between person1 and
person2
if (lengthOfFirstNameOfPerson1 > lengthOfFirstNameOfPerson2){
System.out.println(nameArrayForPerson1[0] +
" has longer first name than " +
nameArrayForPerson2[0]);
}
else
System.out.println(nameArrayForPerson2[0] +
" has longer first name than " +
nameArrayForPerson1[0]);
}
----------------------------------------------------------------------------
On Jan 8, 10:49 pm, Daniel Mays <[email protected]> wrote:
> This is my code:
>
> 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();
>
> nameArrayForPerson1 = JOptionPane.showInputDialog("Please enter your
> name");
> nameArrayForPerson2 = JOptionPane.showInputDialog("Please enter your
> name");
>
> // Compare the lengths of the first names between person1 and
> person2
> if (lengthOfFirstNameOfPerson1 > lengthOfFirstNameOfPerson2){
> System.out.println(nameArrayForPerson1[0] +
> " has longer first name than " +
> nameArrayForPerson2[0]);}
>
> else
> System.out.println(nameArrayForPerson2[0] +
> " has longer first name than " +
> nameArrayForPerson1[0]);
>
> }
>
> I am a little confused because nothing that I have tried is not worked
--
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