It's not a secret anymore!
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
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
It's not a secret anymore!