Hello,
First of all change this line
> String []arr = new String[7];
With
> String []arr = new String[args.length];
This will male tour program able to run with any args passed.
Secondly change
> for(int i = 1; i<arr.length;i++)
with
> for(int i = 0; i<arr.length;i++)
In this way it should work.
I also suggest to always use {} in your for loop, even with just 1 line of code
to male your code more easy to read.
You can also add a for loop to print args values, to verify what is really
passed to your program.
Regard,
TheIrda
Inviato da iPhone
Il giorno 16/ago/2010, alle ore 20:17, henry joseph <[email protected]> ha
scritto:
> Hi,
>
> Even when i start with i= 0, i still dont get the exact number of names
> entered on the command line..
>
> here is my code:
>
>
> public class BuiltInClass {
>
>
> public static void main(String[] args) {
> if(args.length!=5){
> System.out.println("please, names must be 5 on command line!!");
> System.exit(0);
> }
> String []arr = new String[7];
> for(int i = 0; i<args.length;i++)
> arr[i] = args[i];
> for(int i = 1; i<arr.length;i++)
> System.out.println(arr[i]+ " ");
> generateNewName(arr);
>
> here is what i get at my output...
>
> run:
> george
> Hney
> Rroy
> Ayilla
> null
> null
> e
> n
> r
> Exception in thread "main" java.lang.NullPointerException
> y
> at BuiltInClass.generateNewName(BuiltInClass.java:43)
> at BuiltInClass.main(BuiltInClass.java:21)
> Java Result: 1
> BUILD SUCCESSFUL (total time: 3 seconds)
>
>
> i still cant get my zhenny to show.. dont know why, any idea?
>
>
> Dont look at where you fell but where you slipped!!!
>
> --
> 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
--
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