Hi,

Your array are empty. You need to call the InputDialog before you call
the slip method.

Cheers,

Muhammad

On Jan 9, 4:15 pm, Retnuh <[email protected]> wrote:
> Let me see if I can remember this problem off the top of my head. It has been 
> a long time.
> 1. Create Strings to hold the names
> 2. Get the names.
> 3. Create new arrays to hold from the split and then split the names which 
> will create an array of Strings.
> 4. Compare the split first names with each person's first name and print it 
> out.
> // Step 1
> String firstPerson;
> String secondPerson;// Step 2
> firstPerson = JOptionPane.showInputDialog("Please enter your name");
> secondPerson = JOptionPane.showInputDialog("Please enter your name");// Step 3
> // creating the two arrays
> String[] firstPersonName = new String[];
> String[] secondPersonName = new String[];// splitting the two names into the 
> newly created array
> firstPersonName = firstPerson.split(" ");
> secondPersonName = secondPerson.split(" ");// Step 4
> If (firstPersonName[0].length > secondPersonName[0].length) {
>        System.out.println(firstPersonName[0] + " has longer first name than " 
> + secondPersonName[0]);
> } else {
>        System.out.println(secondPersonName[0] + " has longer first name than 
> " + firstPersonName[0])
> }I hope this works... LOL
> If it doesn't, it is darn close and you should build off that.
> Stephen
> PS. Don't just copy it, understand from it. Look at it and see why it is the 
> way it is. I hope the pseudocode at the top helps you out.
> Daniel Mays 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