[java programming] Re: Question on 1036

2009-08-16 Thread mohammed ansari
Hi, I made a little change to Sudhir's code... /** * * @author Salman */ import javax.swing.JOptionPane; public class JavaFirstNameLength { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here

[java programming] Re: Question on 1036

2009-07-23 Thread Tommy Anderson
Dear Sudhir, Yes, glad you got it. I realize that's right, because: name[j].split(" ") will create an array of String, and the first string will be the first string in the array... So you should use "firstName[0]" not "firstName"... But maybe you could change the name of the variable! Tommy

[java programming] Re: Question on 1036

2009-07-22 Thread sudhir Ganesh Paluru
Hello All, I got the program to work.. Thank you all. Most of you were right when you said I had to use firstName[0] always. That was causing the out of bounds issue. Working Code: import javax.swing.JOptionPane; public class ArrayHomeProject { /** * @param args the command line arg

[java programming] Re: Question on 1036

2009-07-22 Thread Tom Anderson
You should use firstName, not firstName[0], since the firstName is selected each time in the loop. On Jul 22, 3:22 pm, Kaka madiba wrote: > You should use firstName[0], since the first name will be at index of 0. Your > error comes up when j =2. --~--~-~--~~~---~--

[java programming] Re: Question on 1036

2009-07-22 Thread Tom Anderson
I think that the error is not the same as the other people have mentioned, since they did not refer to the correct line number. The error message is clear: run: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at ArrayHomeProject.main(ArrayHomeProject.java:28) Java

[java programming] Re: Question on 1036

2009-07-22 Thread erika
2009/7/21 sudhir Ganesh Paluru > 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(S

[java programming] Re: Question on 1036

2009-07-22 Thread Erick Pessoa
Hello All, It would be necessary to instantiate an object JOptionPane to use it? I think yes ... Erick Pessoa 2009/7/21 sudhir Ganesh Paluru > Hello All, > > I am trying out 1036 homework and have the following issue > > code : > _ > > import javax.swing.JOptionPane; > public class ArrayHo

[java programming] Re: Question on 1036

2009-07-22 Thread Kaka madiba
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 wrote: From: sudhir Ganesh Paluru Subject: [java programming] Question on 1036 To: javaprogrammingwithpassion@googlegroups.com Date: Tuesday, J

[java programming] Re: Question on 1036

2009-07-22 Thread Rita
Hi Sudhir, The split method returns an array of Strings which is assigned to your array firstname[]. If the name you entered consists of only a first name, the string array returned has the length 1. If you entered first and last name, the length would be 2. Now in the line "if ((j == 0) || ..."