java question

This is probably a stupid mistake, but I keep getting the error message "ArrayIndexOutOfBoundsException" for this piece of code:
[PHP]public class map
{ public static void main(String args[])
{ int a[][] = new int[3][3];
a[3][0] = 5;
System.out.println(a[3][0]);
}
}[/PHP]

Can you help me out because this the first time I've written in java in over a year and am a little rusty?

Comments

  • edited April 2007
    O. and this code passes when i compile it. It gives me the error message when i run it.
  • airbornflghtairbornflght Houston, TX Icrontian
    edited April 2007
    ok, your array is a a two dimensional square array that is 3x3, which means the indexes(sp) go: 0,1,2; therefore there is no "3,0" So its out of bounds. Remember, when you're programming start counting from 0. It should be "2,0"

    The reason it compiles is that there is nothing syntactically wrong with that code.

    zz 0 1 2
    0|* * *
    1|* * *
    2|* * *
  • edited April 2007
    thanx
Sign In or Register to comment.