/**
* @param args
*/
private int[][] mar;
private int row;
private int col;
public Marix(int i,int j){
this.mar = new int[i][j];
this.row = i;
this.col = j;
}
public int getElement(int i,int j) throws Exception{
if(i>this.row || j>this.col)
throw new Exception("index out of bound.");
return mar[i][j];
}
public void setElement(int i,int j,int val) throws Exception{
if(i>this.row || j>this.col)
throw new Exception("index out of bound.");
mar[i][j]=val;
}
public Marix add(Marix another) throws Exception
{
if(this.row != another.row || this.col != another.col)
throw new Exception("the row or col is not equal.");
Marix ret = new Marix(this.row, this.col);
for(int i=0; i<this.row; i++)
{
for(int j=0; j<this.col; j++)
ret.setElement(i, j, this.getElement(i, j) + another.getElement(i, j));
}
return ret;
}
public Marix multiply(Marix another) throws Exception
{
if(this.row != another.col)
throw new Exception("the row is not equal to col.");
Marix ret = new Marix(this.row, this.col);
int temp =0;
for(int i=0; i<this.row; i++)
{
temp = 0;
for(int j=0; j<this.row; j++)
{
for(int k=0; k<another.col; k++)
temp += this.getElement(i, k) * another.getElement(k, j);
ret.setElement(i, j, temp);
}
}
return ret;
}