Subject: Re: Homework 1, minor difficulty

From: Chee Yap <[email-masked]>
Date: Fri, 17 Sep 1999 15:02:40 -0400 (EDT)

args[0] is the first argument.
So if you have one one argument, args[1] is out of bounds.
So you cannot use the comparison to null to detect
the number of arguments.
Look in our Hello.java program for the proper way
to do this.

Chee

> From [email-masked] Fri Sep 17 12:04 EDT 1999
> Date: Fri, 17 Sep 1999 12:04:12 -0400 (EDT)
> From: Will Wehner <[email-masked]>
> To: [email-masked]
> cc: [email-masked]
> Subject: Homework 1, minor difficulty
> 
> Mr. Rudra;
> 
> 	Hello, my name is Will Wehner, I am in Prof. Yap's
> Basic Algorithm's class.  I was working on the assignment and
> attempting to check if there was more than one argument. While
> I am able to do that successfully, now whenever my program is
> passed only one argument, I get an ArrayIndexOutOfBounds exception!
> My code was working before I accessed this part of the array.
> This is what my code looks like:
> 
> // Previous Code...
>     if (args[1] != null) {
>       System.out.println
>        ("You must enter only one argument to run this program!");
>       System.out.println
>        ("Please try again with one integer argument.\n");
>     } else {
>       // Rest of Code..
> 
> Is there any way I can avoid this error, or do I have to add another
> catch to my code to deal with this exception? Thanks in advance..
> 
> 
> Will Wehner
> 
>