java program to subtract two matrix

      1 Comment on java program to subtract two matrix

Subtract two matrix

This program illustrate the concept to Subtract two matrix

  • Here in this program “i” is number of rows and “j” is number of coloumns.
  • “a[3][3]” is the name of first matrix with 3 rows and 3 coloumns .
  • “b[3][3]” is the name of second matrix with 3 rows and 3 coloumns .
  • “c[3][3]” is the name of resultant matrix with 3 rows and 3 coloumns .In this array result will be stored.
import java.util.*;
class scan
{
	public static void main(String arg[])
	{
 int a[][]=new int[3][3];
 int b[][]=new int[3][3];
 int c[][]=new int[3][3];
 int i,j;
 Scanner kb=new Scanner(System.in);
 System.out.println("Enter First Matrice row wise:-\n");
 
 for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
    {
     a[i][j]=kb.nextInt();
    }
  }
 
  System.out.println("Enter Second Matrice row wise:-\n");
 
 for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
    {
     b[i][j]=kb.nextInt();
    }
  }
 for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
    {
     c[i][j]=a[i][j]-b[i][j];
    }
  }
 
  System.out.println("Subtraction of Matrice is:-");
  for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
    {
     System.out.print("     "+c[i][j]);
 
    }
    System.out.println();
  }
}
}

OUTPUT:-

subtract two matrix


Comment below if you are facing any problem.


Also read

java program to print a matrix in 2d array
Java program to transpose a matrix


Summary
java program to subtract two matrix
Article Name
java program to subtract two matrix
Description
This program illustrate the concept to subtract two matrix.Here in this program “i” is number of rows and “j” is number of coloumns.
Author
Publisher Name
Scanfcode
Publisher Logo

1 comment on “java program to subtract two matrix

  1. bad Jokes

    Awesome blog! Do you have any helpful hints for aspiring writers?

    I’m planning to start my own website soon but
    I’m a little lost on everything. Would you propose starting with a free platform like WordPress
    or go for a paid option? There are so many choices out there that I’m completely overwhelmed ..
    Any recommendations? Appreciate it!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *