i cant seem to get this to wrong.. one or the other goes wrong..can
someone tlel me whats worng with this code


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

 */
import javax.swing.*;

public class MyJavaArray {

    public static void main(String[] args) {

           // Step 1
        String firstPerson;
        String secondPerson;
        String thirdPerson;

        // Step 2
        firstPerson = JOptionPane.showInputDialog("Please enter your
name");
        secondPerson = JOptionPane.showInputDialog("Please enter your
name");
        thirdPerson = JOptionPane.showInputDialog("Please enter your
name");


//Step 3
        // creating the two arrays
        String[] firstPersonName = new String[2];
        String[] secondPersonName = new String[2];
        String[] thirdPersonName = new String[2];
        // splitting the two names into the newly created array
        firstPersonName = firstPerson.split(" ");
        secondPersonName = secondPerson.split(" ");
        thirdPersonName = thirdPerson.split(" ");

        // Step 4
        if (firstPersonName[0].length() >
secondPersonName[0].length() )
           if (firstPersonName[0].length() <
thirdPersonName[0].length()) {
               System.out.println(thirdPersonName[0] + " has longer
first name than " + secondPersonName[0] + " and " +
firstPersonName[0]);

        } if (firstPersonName[0].length() ==
secondPersonName[0].length()) {
               System.out.println(secondPersonName[0] + "'s first name
is the same length as " + firstPersonName[0] + "'s first name.");
         } else if (firstPersonName[0].length() ==
thirdPersonName[0].length()) {
               System.out.println(thirdPersonName[0] + "'s first name
is the same length as " + firstPersonName[0] + "'s first name.");
    } else if (secondPersonName[0].length() >
thirdPersonName[0].length()) {
               System.out.println(secondPersonName[0] + " has longer
first name than " + thirdPersonName[0] + " and " +
firstPersonName[0]);
          } else
               System.out.println(firstPersonName[0] + " has longer
name than  " + secondPersonName[0] + " and " + thirdPersonName[0]);




        }
    }


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