Ways To Print Metrix Program in JAVA ( Addition, Subtraction, Multiply) | Learn by Java2021 - Java2021 : Online Tutorials Hub

Java2021 : Online Tutorials Hub

JAVA | Advance Java | MySQL | Data Structure | Git | HTML | CSS | JS

Latest

Post Top Ad

Saturday, June 20, 2020

Ways To Print Metrix Program in JAVA ( Addition, Subtraction, Multiply) | Learn by Java2021

Write a program to print addition of two metrix

public class Addmetrix {
    public static void main(String[] args)
    {
        int a[][]={{3,4,2},{4,5,6},{7,8,9}};
        int b[][]={{3,4,2},{4,1,2},{7,8,9}};
        int add[][]=new int[3][3];
        for (int i=0;i<a.length;i++){
            for (int j=0;j<b.length;j++){
                add[i][j]=0;
                for (int k=0;k<add.length;k++){
                    add[i][j]=a[i][k]+b[k][j];
                }
                System.out.print(add[i][j]+" ");
            }
            System.out.println();
        }
    }
}
OUTPUT  : 

Write a program to print Multiplication of two metrix
public class Mulmetrix {
    public static void main(String[] args)
    {
        int a[][]={{3,4,2},{4,5,6},{7,8,9}};
        int b[][]={{3,4,2},{4,1,2},{7,8,9}};
        int add[][]=new int[3][3];
        for (int i=0;i<a.length;i++){
            for (int j=0;j<b.length;j++){
                add[i][j]=0;
                for (int k=0;k<add.length;k++){
                    add[i][j]=a[i][k]*b[k][j];
                }
                System.out.print(add[i][j]+" ");
            }
            System.out.println();
        }
    }
} 
OUTPUT : 
Write a program to print Subtraction of two metrix
public class Submetrix {
    public static void main(String[] args)
    {
        int a[][]={{3,4,2},{4,5,6},{7,8,9}};
        int b[][]={{3,4,2},{4,1,2},{7,8,9}};
        int add[][]=new int[3][3];
        for (int i=0;i<a.length;i++){
            for (int j=0;j<b.length;j++){
                add[i][j]=0;
                for (int k=0;k<add.length;k++){
                    add[i][j]=a[i][k]-b[k][j];
                }
                System.out.print(add[i][j]+" ");
            }
            System.out.println();
        }
    }
} 
OUTPUT : 

-Important Programs for Freshers

Sorting and Searching Programs

Learn Pattern Programs 
Click to Learn MySQL 
for any complaint regarding my Blog please visit contact us page and write what problem you have!

No comments:

Pages