the personNameInstance is for contain the name of the person and this
variables is not initialized with the names of persons (you need load
the names in the dialog box in this variables), and the
nameArrayForPerson is for split the first and the second name in this
array of string, look this code:

String person1NameInstance,person2NameInstance;
String[] nameArrayForPerson1;
String[] nameArrayForPerson2;

person1NameInstance = JOptionPane.showInputDialog("Please enter your
name");
person2NameInstance = JOptionPane.showInputDialog("Please enter your
name");

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

Reply via email to