I made a little change to your programme with an aditional int variable:

import javax.swing.JOptionPane;
public class OwnJavaArray {
    /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            int counter,max=0;
            String[][] nameArrayForPerson= new String[3][2];
            int[] lengthOfFirstNameOfPerson=new int[3];
            int maxIndex = 0;

            for(counter=0;counter<=2;counter++)
            {

nameArrayForPerson[counter]=(JOptionPane.showInputDialog("Enter your full
name giving space between them").split(" "));

lengthOfFirstNameOfPerson[counter]=nameArrayForPerson[counter][0].length();
            }



             for(counter=0;counter<3;counter++)
            {

                if(lengthOfFirstNameOfPerson[counter] > max){
                    max = lengthOfFirstNameOfPerson[counter];
                    maxIndex = counter;
                }
             }


JOptionPane.showMessageDialog(null,nameArrayForPerson[maxIndex][0] + "  has
longest first name");

        }
}


On Sat, Nov 15, 2008 at 8:22 AM, Sailaja K <[EMAIL PROTECTED]>wrote:

>   Hello friends,
>
> I have solved the homework question in this way
>
> import javax.swing.JOptionPane;
>
> public class OwnJavaArray {
>
>     /**
>      * @param args the command line arguments
>      */
>     public static void main(String[] args) {
>         int counter,max=0;
>         String[][] nameArrayForPerson= new String[3][2];
>         int[] lengthOfFirstNameOfPerson=new int[3];
>
>         for(counter=0;counter<=2;counter++)
>         {
>            nameArrayForPerson[counter]=(JOptionPane.showInputDialog("Enter
> your full name giving space between them").split(" "));
>
> lengthOfFirstNameOfPerson[counter]=nameArrayForPerson[counter][0].length();
>         }
>
>
>
>          for(counter=0;counter<3;counter++)
>         {
>             if(lengthOfFirstNameOfPerson[counter] > max)
>                 max = counter;
>          }
>
>         JOptionPane.showMessageDialog(null,nameArrayForPerson[max] + "  has
> longest first name");
>
>     }
>
> }
>
>
>
>
>
>
> It is comparing in a correct way but while printing the name of the person
> giving som garbage value.
> Please help me .
>
>
> ------------------------------
> Add more friends to your messenger and enjoy! Invite them now.
> >
>
> <http://in.rd.yahoo.com/tagline_messenger_6/*http://messenger.yahoo.com/invite/>

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