Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Java program to subtract two matrices

In this post, we will see how to subtract two matrices in java.I am giving example for 3*3 Matrix. You can extend it to n*n matrices.

import java.util.Scanner;

public class MatrixOperator
{
   public static void main(String args[])
   {
       int i, j;
       int mat1[][] = new int[3][3];
       int mat2[][] = new int[3][3];
       int res[][] = new int[3][3];
       Scanner scanner = new Scanner(System.in);
	   
       System.out.print("Enter Matrix 1 Elements : ");
       for(i=0; i

Output:

Enter Matrix 1 Elements : 11 22 33 44 55 66 77 88 99
Enter Matrix 2 Elements : 10 20 30 40 50 60 70 80 90
New Matrix is :
1 2 3
4 5 6
7 8 9

The post Java program to subtract two matrices appeared first on Java2Blog.



This post first appeared on How To Learn Java Programming, please read the originial post: here

Share the post

Java program to subtract two matrices

×

Subscribe to How To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×