Hi vbrun, I think u have made mistake while using split method. There should be " " i.e space between the quotes ( " " ) not ( "") so as to separate out firstName with the lastName.
Also in the end you have written System.out.println(firstName1); it will just print the className@hashcode .To resolve this write System.out.println(firstName1[0]); . This is because firstName1 is String array object whose toString() method is not overridden while firstName1[0] is just a simple String object whose toString() method is overridden to print the actual string value . --------- On Thu, Jan 27, 2011 at 5:50 PM, victor bruno <vb...@hotmail.com> wrote: > Hi fellows! Hope everybody is doing great. > I'm solving the java Array lab and this far wrote the following code: > > String[] namePerson1 = new String[2]; > String[] namePerson2 = new String[2]; > String[] namePerson3 = new String[2]; > int i =0; > > > // creates a loop for the user to insert first name > for( i=0; i<namePerson1.length; i++){ > namePerson1[i] = JOptionPane.showInputDialog > ("Please Enter First and Last Name "); > break; > } > > // For loop to insert second name > for ( i= 0; i< namePerson2.length; i++){ > namePerson2[i]=JOptionPane.showInputDialog > ("Please Enter 2nd First and Last Name "); > break; > } > > for( i =0; i<namePerson3.length; i++){ > namePerson3[i]=JOptionPane.showInputDialog > (" Please Enter 3rd First and Last Name "); > break; > } > > //obtain the first name in array using split method > String[] firstName1 = namePerson1[i].split(""); > String[] firstName2 = namePerson2[i].split(""); > String[] firstName3 = namePerson3[i].split(""); > > //get the lengths of first names using length method of String > Class > int lengthOfName1 = firstName1[0].length(); > int lengthOfName2 = firstName2[0].length(); > int lengthOfName3 = firstName3[0].length(); > > // compare the length and returns the longest first name > //display the results > > > if((lengthOfName1 > lengthOfName2) && (lengthOfName1 > > lengthOfName3)) > > System.out.println(" Longest first name entered is " > + firstName1[0] ); > > else if((lengthOfName2 > lengthOfName1) &&(lengthOfName2 > > lengthOfName3)) > System.out.println(" Longest first name entered is " > + firstName2[0]); > > else if ((lengthOfName3 > lengthOfName1)&&(lengthOfName3 > > lengthOfName2)) > System.out.println(" Longest first name entered is " > + firstName3[0]); > //else > //System.out.println("Maybe 2 or more names have the same > length"); > // last line > System.out.println(firstName1); > > > And it has no output.The last line I inserted just to test the code,as a > result I got the following output: [Ljava.lang.String;@a0dcd9. > > What's wrong please? > Thank you, > > > > > > > > > > > > > > > > > > > > > > -- > To post to this group, send email to > javaprogrammingwithpassion@googlegroups.com > To unsubscribe from this group, send email to > javaprogrammingwithpassion+unsubscr...@googlegroups.com<javaprogrammingwithpassion%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/javaprogrammingwithpassion?hl=en -- * * *Regards* *Nikhil Srivastava | Software Engineering | GlobalLogic Inc. ** The Global Product Development Leader* *USA** | INDIA | UKRAINE | CHINA* *B - 34/1, Sector - 59, Noida (UP)* *Office: +91-120-434-2000 x <2448> | Mobile +91-9560727845* *www.globallogic.com* *InfoWorld Award Winner for Agile Innovation* ----------------------------------------------------------------------------------------------------------------------------------------------- *Backed by Sequoia, NEA and New Atlantic Ventures (part of the DFJ network), GlobalLogic partners with emerging and established technology companies to help them accelerate great products to market.** **GlobalLogic has developed a unique model that combines distributed Agile methods, innovative open source-based tools, and global teams of world-class engineers to dramatically shorten product development cycles. GlobalLogic has ongoing partnerships with more than 140 technology companies and has completed over 800 major product releases over the past six years, including 300 in the last 12 months with a better than 95% on-time delivery. Headquartered in Vienna,Virginia, GlobalLogic has global development centers in the US, India, China and Ukraine. By leveraging its InfoWorld award-winning method and platform, GlobalLogic Velocity™, its global facilities and world-class engineers, clients gain rapid time-to-market, improved quality and reduced development expense. * *Disclaimer: **http://www.globallogic.com/email_disclaimer.txt* -- To post to this group, send email to javaprogrammingwithpassion@googlegroups.com To unsubscribe from this group, send email to javaprogrammingwithpassion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en