You should use firstName[0], since the first name will be at index of 0. Your error comes up when j =2.
--- On Tue, 7/21/09, sudhir Ganesh Paluru <[email protected]> wrote: From: sudhir Ganesh Paluru <[email protected]> Subject: [java programming] Question on 1036 To: [email protected] Date: Tuesday, July 21, 2009, 4:25 PM Hello All, I am trying out 1036 homework and have the following issue code : _____ import javax.swing.JOptionPane; public class ArrayHomeProject { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here String name[] = new String[3]; // String firstName[] = new String[6]; String max = ""; for (int i=0;i<3;i++) { name[i] = JOptionPane.showInputDialog("Enter threee names"+i); } for (int j=0;j<3;j++) { String firstName[] = name[j].split(" "); if((j==0)||(max.length()>firstName[j].length())) { max = firstName[j]; } } System.out.println("The longest first name is"+max); } } Error Message when i run it: ___________________________ run: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at ArrayHomeProject.main(ArrayHomeProject.java:28) Java Result: 1 Any pointers would be appreciated. Thanks, Sudhir --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
