Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mid1;
- import java.util.Scanner;
- public class MatrixOperation {
- private static int outputMatrx[][]= new int [3][3];
- public static void main(String[] args) {
- Matrix mat= new Matrix();
- Matrix mat1= new Matrix();
- Scanner ac = new Scanner (System.in);
- int i , j ;
- for(i=0;i<3;i++) {
- for(j=0;j<3;j++) {
- mat.matrix[i][j]=ac.nextInt();
- }
- }
- for(i=0;i<3;i++) {
- for(j=0;j<3;j++) {
- mat1.matrix[i][j]=ac.nextInt();
- }
- }
- outputMatrx=mat.matrixOp(mat1);
- Matrix.print(outputMatrx);
- System.out.println(" Number of Objects created "+mat.getNumberOfObjects());
- }
- }
- class Matrix{
- public int matrix[][]=new int[3][3];
- private static int numberOfObjects=0;
- Matrix() {
- numberOfObjects++;
- }
- public int getNumberOfObjects(){
- return numberOfObjects;
- }
- public int [][]matrixOp(Matrix ob) {
- int i,j;
- int b[][]= new int [3][3];
- for(i=0;i<3;i++) {
- for(j=0; j<3;j++) {
- b[i][j]=Math.abs(ob.matrix[i][j]-this.matrix[i][j]);
- }
- }
- return b;
- }
- public static void print(int mat[][] ) {
- System.out.printf(" output");
- for(int i=0;i<3;i++) {
- for(int j=0; j<3;j++) {
- System.out.printf(" %d",mat[i][j]);
- }
- System.out.printf("\n");
- }
- System.out.printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement