- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to subtract two matrices.
Following is the required program.
Example
public class Tester { public static void main(String args[]) { //matrix 1 int a[][] = { { 1, 3, 4 }, { 2, 4, 3 }, { 3, 4, 5 } }; //matrix 2 int b[][] = { { 1, 3, 4 }, { 2, 4, 3 }, { 1, 2, 4 } }; //result matrix int c[][] = new int[3][3]; // 3 rows and 3 columns // subtract and print matrix for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { c[i][j] = a[i][j] - b[i][j]; System.out.print(c[i][j] + " "); } System.out.println(); } } }
Output
0 0 0 0 0 0 2 2 1
- Related Articles
- Java program to add two matrices.
- Java program to multiply two matrices.
- How to write Java program to add two matrices
- Java program to check if two given matrices are identical
- C# program to multiply two matrices
- C# program to add two matrices
- Python program to multiply two matrices
- Golang Program To Add Two Matrices
- Program to multiply two matrices in C++
- Program for subtracting two matrices.
- C# Program to Subtract Two TimeSpan
- C++ Program to Check Multiplicability of Two Matrices
- 8085 program to subtract two BCD numbers
- Multiplication of two Matrices using Java
- C# program to check if two matrices are identical

Advertisements