Advertisement
Huntersazzad

mATRIXOP

Nov 24th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package mid1;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class MatrixOperation {
  6.    
  7. private static int outputMatrx[][]= new int [3][3];
  8.     public static void main(String[] args) {
  9.        
  10.        
  11.         Matrix mat= new Matrix();
  12.         Matrix mat1= new Matrix();
  13.         Scanner ac = new Scanner (System.in);
  14.         int i , j ;
  15.         for(i=0;i<3;i++) {
  16.             for(j=0;j<3;j++) {
  17.                
  18.             mat.matrix[i][j]=ac.nextInt(); 
  19.             }
  20.         }
  21.        
  22.         for(i=0;i<3;i++) {
  23.             for(j=0;j<3;j++) {
  24.                
  25.             mat1.matrix[i][j]=ac.nextInt();
  26.             }
  27.         }
  28.         outputMatrx=mat.matrixOp(mat1);
  29.         Matrix.print(outputMatrx);
  30.         System.out.println("  Number of Objects created    "+mat.getNumberOfObjects());
  31.        
  32.        
  33.        
  34.        
  35.  
  36.     }
  37.  
  38. }
  39. class Matrix{
  40.     public int matrix[][]=new int[3][3];
  41.  
  42.     private static int numberOfObjects=0;
  43.    
  44.     Matrix() {
  45.         numberOfObjects++;
  46.     }
  47. public int  getNumberOfObjects(){
  48.    
  49.  return numberOfObjects;
  50. }
  51.    
  52.     public int  [][]matrixOp(Matrix ob) {
  53.        
  54.         int i,j;
  55.         int b[][]= new int [3][3];
  56.        
  57.         for(i=0;i<3;i++) {
  58.         for(j=0; j<3;j++) {
  59.         b[i][j]=Math.abs(ob.matrix[i][j]-this.matrix[i][j]);
  60.         }  
  61.     }
  62.     return b;
  63.     }
  64. public static void  print(int mat[][] ) {
  65.     System.out.printf(" output");
  66.    
  67.     for(int i=0;i<3;i++) {
  68.         for(int j=0; j<3;j++) {
  69.             System.out.printf(" %d",mat[i][j]);
  70.            
  71.        
  72.         }
  73.         System.out.printf("\n");   
  74.     }
  75.     System.out.printf("\n");
  76.    
  77. }
  78.  
  79.    
  80.    
  81.    
  82.    
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement