Java Matrix
Java Matrix
Scanner;
if((row1==row2)&&(col1==col2)){
System.out.println("Matrix 1:");
for(int x=0; x<row1; x++){
for(int y=0; y<col1; y++){
System.out.print("Matrix1["+ x +"]" +"[" + y +"]");
matrix1[x][y]=in.nextInt();
}
}
System.out.println("Matrix 2:");
for(int x=0; x<row2; x++){
for(int y=0; y<col2; y++){
System.out.print("Matrix2["+ x +"]" +"[" + y +"]");
matrix2[x][y]=in.nextInt();
}
}
for(int x=0; x<row2; x++){
for(int y=0; y<col2; y++){
answer[x][y]=matrix1[x][y] + matrix2[x][y];
}
}
for(int x=0; x<row2; x++){
System.out.println();
for(int y=0; y<col2; y++){
}
}
System.out.println("Transposition");
System.out.println("Matrix 1");
for(int x=0; x<row1; x++){
System.out.println();
for(int y=0; y<col1; y++){
System.out.print(matrix1[y][x]+ " ");
}
}
System.out.println("Matrix 2");
for(int x=0; x<row2; x++){
System.out.println();
for(int y=0; y<col2; y++){
System.out.print(matrix2[y][x]+" ");
}
}
System.out.println("Enter number:");
n=in.nextInt();
System.out.println("Scalar Multiplication:");
for(int x=0; x<row1; x++){
for(int y=0; y<col1; y++){
answer[x][y]= n * matrix1[x][y];
}
}
if(col1==row2) {
System.out.println("Matrix 1:");
for(int x=0; x<row1; x++){
for(int y=0; y<col1; y++){
System.out.print("Matrix1["+ x +"]" +"[" + y +"]");
matrix1[x][y]=in.nextInt();
}
}
System.out.println("Matrix 2:");
for(int x=0; x<row2; x++){
for(int y=0; y<col2; y++){
System.out.print("Matrix2["+ x +"]" +"[" + y +"]");
matrix2[x][y]=in.nextInt();
}
}
}
else{
System.out.print("Can't Perform Multiplication of Matrix");
}
}
}