Here you go!!!! See the highlighted changes ...

Let me know if you have questions

Cheers
-Dasa





import javax.swing.JOptionPane;

import javax.swing.JOptionPane;

public class OwnJavaArray {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int counter,max = 0;

// EDIT
        int NameLength=0;

// END-OF-EDIT

        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++)
        {

// FIXED THE LOGIC HERE

            if((counter==0)||(lengthOfFirstNameOfPerson[counter] >
NameLength)){
             NameLength = lengthOfFirstNameOfPerson[counter];
                max = counter;
            }
         }

//EDITED THE FOLLOWING LINE ... INCLUDED SECOND DIMENSION FOR A 2-D ARRAY

        String msg = nameArrayForPerson[max][0]+"  has longest first name";
        JOptionPane.showMessageDialog(null,msg);

    }

    }


On Fri, Nov 14, 2008 at 9:52 PM, 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