public class cl_gm {
public static void main(String[] args) {
int num = Integer.parseInt(args[0]);
if(num==1 || num==3 || num==5 || num==7 || num==8 || num==10 || num==12)
System.out.println(31);
else if(num==4 || num==6 || num==9 || num==11)
System.out.println(30);
else if(num==2)
System.out.println(28);
else
System.out.println("il numero deve essere compreso tra 1 e 12");
}
}
java.lang.ArrayIndexOutOfBoundsException: 0
at cl_gm.main(cl_gm.java:3)
Exception in thread "main"
Thankyou for any suggestion!
Thomas Hawtin - 19 Mar 2006 22:11 GMT
> java.lang.ArrayIndexOutOfBoundsException: 0
> at cl_gm.main(cl_gm.java:3)
> Exception in thread "main"
You need to supply the month number on the command line, after the class
name:
java cl_gm 2
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Rob Skedgell - 19 Mar 2006 22:49 GMT
> public class cl_gm {
> public static void main(String[] args) {
> int num = Integer.parseInt(args[0]);
[...snip...]
> java.lang.ArrayIndexOutOfBoundsException: 0
> at cl_gm.main(cl_gm.java:3)
> Exception in thread "main"
>
> Thankyou for any suggestion!
You need to pass the month number as an argument, like this for the
length of March:
java cl_gm 3
31
If you just run
java cl_gm
the String array passed to the main method as args[] will be empty, so
args[0] will be outside the array, and the
ArrayIndexOutOfBoundsException is thrown because of this.
You may wish to familiarise yourself with the javadoc for the exception
<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ArrayIndexOutOfBoundsException.html>

Signature
Rob Skedgell <rob+news@nephelococcygia.demon.co.uk>
All posts made via GoogleGropes killfiled, sorry.
GnuPG/PGP: 7DA3 1579 C0DD 8748 C05A B984 E2A2 3234 D14B 6DD7
jcsnippets.atspace.com - 19 Mar 2006 23:09 GMT
> public class cl_gm {
> public static void main(String[] args) {
[quoted text clipped - 15 lines]
>
> Thankyou for any suggestion!
I suspect that, as Thomas already pointed out, you did not supply a value
for args[0]. In other words, you started your program using "java cl_gm"
instead of "java cl_gm 2".
If you start your program like in the first example, the array args will be
null, and there will be no element at index 0, hence the
ArrayIndexOutOfBoundsException.
Posting code of what you are having problems with, is a Good Thing (tm). But
next time you post a question, it might be a good idea to also post a little
description of what you are doing (what is the purpose of your code, what
did you expect it to do, etc...). This clarifies the situation for people
who want to help, and gives them a bigger lead to start from.
Best regards,
JayCee
--
http://jcsnippets.atspace.com/
a collection of source code, tips and tricks
Rob Skedgell - 19 Mar 2006 23:47 GMT
[...]
> If you start your program like in the first example, the array args
> will be null, and there will be no element at index 0, hence the
^^^^
> ArrayIndexOutOfBoundsException.
Shouldn't that be "empty", not "null"?

Signature
Rob Skedgell <rob+news@nephelococcygia.demon.co.uk>
All posts made via GoogleGropes killfiled, sorry.
GnuPG/PGP: 7DA3 1579 C0DD 8748 C05A B984 E2A2 3234 D14B 6DD7
jcsnippets.atspace.com - 22 Mar 2006 00:10 GMT
> [...]
> > If you start your program like in the first example, the array args
[quoted text clipped - 3 lines]
>
> Shouldn't that be "empty", not "null"?
Rob,
Indeed - my mistake. The array args will of course be empty, not null.
Best regards,
JC
--
http://jcsnippets.atspace.com/
a collection of source code, tips and tricks
NewsFree - 20 Mar 2006 00:12 GMT
Thankyou! Thankyou, very helpful people...(I need to improve my Java and my
English too! :)
Roedy Green - 20 Mar 2006 02:19 GMT
>ArrayIndexOutOfBoundsException
for this and other messages, see
http://mindprod.com/jgloss/runerrormessages.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.