This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes matrix array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "matrix array" Watch "matrix array" New topic

matrix array

dejie lin
Ranch Hand

Joined: Jan 29, 2003
Posts: 31
hi all,
i have defined a class "matrix" by my self, i wanna have an array of matrix, the code is in the following:
matrix[][] m=new matrix[20][15];
for(int i=0;i<20;i++)
for(int j=0;j<20;j++)
m[i][j] = new matrix();
class matrix
public int type;
public int NodeNo;
public matrix()
NodeNo =0;
void settype(int t)
type =t;
void setNodeNo(int n)
NodeNo =n;
Problem : there's no compiling error, but there will be arrayIndexOutOfBoundsException ....
Anybody can help me?
Ashish Hareet
Ranch Hand

Joined: Jul 14, 2001
Posts: 375
Hi Dejie,
j will max out at 14 so j < 20 is gonna throw an exception, it should read j < 15.
A better approach would be -

I don't think I have got this wrong, but do check, no JVM on this machine.
Ashish Hareet
I agree. Here's the link:
subject: matrix array