Display of matrices by using various methods
There was a question somewhere on the net that I had to display matrices using different constructors as in default type, input parameter as matrix, input parameter as object instance of that matrix but I am getting a run time error . The program is as follows
class MatrixEx1{
int mat[][];
MatrixEx1() {
int i,j;
int row=3;
int col=3;
mat=new int[3][3];
for(i=0;i<row;i ) {
for(j=0;j<col;j ) {
mat[i][j]=i*j;
System.out.println(mat[i][j]);
}
}}
MatrixEx1(int r, int c) {
int i,j;
for (i=0;i<r;i ) {
for(j=0;j<c;j ) {
mat[i][j]=1;
System.out.println(mat[i][j]);
}
}}
MatrixEx1(int mat1[][]) {
int r=mat1.length;
int c=mat1[0].length;
for (int i=0; i<r;i )
{
for(int j=0;j<c;j ) {
mat[i][j]=mat1[i][j];
System.out.println(mat[i][j]);
}
System.out.println(" ");
} }
MatrixEx1(MatrixEx1 m1) {
int r=m1.mat.length;
int c=m1.mat[0].length;
for (int i=0;i<r;i )
{
for(int j=0;j<c;j )
{
mat[i][j]=m1.mat[i][j];
System.out.println(mat[i][j]);
}
} }
}
class MainClasss {
public static void main(String args[]) {
int m3[][] = {{1,3,5},{2,3,1},{4,5,6}};
MatrixEx1 m1=new MatrixEx1(m3);
MatrixEx1 m2=new MatrixEx1(MatrixEx1 m1);
} }
The errors are:
MatrixEx1 m2=new MatrixEx1(MatrixEx1 m1);
^
MainClasss.java:51: illegal start of expression
MatrixEx1 m2=new MatrixEx1(MatrixEx1 m1);
Can you please rectify this program?