The garbage that you are printing is the pionter to the second array.
You have a 2D array, so if you want to print out the values of that
array, you need to the cells from the second index. Try
JOptionPane.showMessageDialog(null,nameArrayForPerson[max][0] + "
"+nameArrayForPerson[max][1] +" has longest first name");
On Nov 14, 6: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 .
>
> Connect with friends all over the world. Get Yahoo! India Messenger
> athttp://in.messenger.yahoo.com/?wm=n/
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---