Java Program to Check Multiplicability of Two Matrices

This is the java program to check the multiplication of the two matrices. Two matrices are multiplicable if and only if the number of rows of the left hand side matrix is equal to the number of columns of the right hand side matrix.

Here is the source code of the Java Program to Check Multiplicability of Two Matrices. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

//This is sample program to find out whether the two matrices are multiplicable or not
//The complexity of the code is O(n)(linear)
import java.util.Scanner;
 
public class Multiplicability_Matrix 
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the dimension of the matrix:\n ");
        int rowA = sc.nextInt();
        int colA = sc.nextInt();
 
        System.out.println("Enter the dimension of the other matrix:\n ");
        int rowB = sc.nextInt();
        int colB = sc.nextInt();
 
        if(colA == rowB)
        {
            System.out.println("Matrices are multipilcable");
        }
        else
        {
            System.out.println("Matrices are not multipilcable");
        }
        sc.close();
 
    }
}

Output:

$ javac Muliplicability_Matrix.java
$ java Muliplicability_Matrix
Enter the dimension of the matrix:
1 2
Enter the dimension of the other matrix:
2 3
Matrices are multipilcable

Related posts:

Guide to CountDownLatch in Java
Java Program to Apply Above-Below-on Test to Find the Position of a Point with respect to a Line
Entity To DTO Conversion for a Spring REST API
Exploring the Spring Boot TestRestTemplate
Java Program to Implement PriorityQueue API
XML Serialization and Deserialization with Jackson
Java Program to Construct an Expression Tree for an Infix Expression
Java Program to Implement Selection Sort
Java Program to Implement Johnson’s Algorithm
OAuth2 for a Spring REST API – Handle the Refresh Token in AngularJS
REST Web service: Upload và Download file với Jersey 2.x
Compare Two JSON Objects with Jackson
Java – Reader to InputStream
Comparing Objects in Java
Hướng dẫn Java Design Pattern – Proxy
Lớp TreeMap trong Java
Converting a Stack Trace to a String in Java
Allow user:password in URL
Java Program to Perform integer Partition for a Specific Case
JUnit 5 for Kotlin Developers
Creating a Generic Array in Java
Hướng dẫn Java Design Pattern – Factory Method
The Dining Philosophers Problem in Java
Java Program to Perform Stooge Sort
Java Program to Implement the Binary Counting Method to Generate Subsets of a Set
Serverless Functions with Spring Cloud Function
Java Program to Print the Kind of Rotation the AVL Tree is Undergoing
Tính đóng gói (Encapsulation) trong java
Java Program to Implement an Algorithm to Find the Global min Cut in a Graph
Guide to the Fork/Join Framework in Java
Java Program to Compute DFT Coefficients Directly
HttpClient Basic Authentication