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:

Fixing 401s with CORS Preflights and Spring Security
Hashing a Password in Java
XML Serialization and Deserialization with Jackson
Java Program to Implement Ternary Search Algorithm
Java Program to Implement DelayQueue API
Java Program to Represent Graph Using Incidence Matrix
Java Program to Check the Connectivity of Graph Using BFS
Java Program to Perform Insertion in a 2 Dimension K-D Tree
Java Program to Find Nearest Neighbor Using Linear Search
Java Program to Implement IdentityHashMap API
Java Program to Find Location of a Point Placed in Three Dimensions Using K-D Trees
Java Program to Generate a Random UnDirected Graph for a Given Number of Edges
Java Program to Find Inverse of a Matrix
Tránh lỗi NullPointerException trong Java như thế nào?
Spring REST API + OAuth2 + Angular
Service Registration with Eureka
Java Program to Give an Implementation of the Traditional Chinese Postman Problem
Java Program to Perform Partial Key Search in a K-D Tree
Database Migrations with Flyway
Vòng lặp for, while, do-while trong Java
Lớp lồng nhau trong java (Java inner class)
Setting Up Swagger 2 with a Spring REST API
Java 8 Stream findFirst() vs. findAny()
Java Program to Implement PrinterStateReasons API
Java – Write a Reader to File
A Guide to Java 9 Modularity
Java Program to Perform the Sorting Using Counting Sort
How to Get a Name of a Method Being Executed?
@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll
Serialize Only Fields that meet a Custom Criteria with Jackson
Java Program to Represent Graph Using Linked List
Java Program to Implement Euclid GCD Algorithm