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:

Java Program to Implement Tarjan Algorithm
Spring Webflux with Kotlin
Java Program to Implement Nth Root Algorithm
Spring Boot - Building RESTful Web Services
Java Program to Implement Binomial Heap
Primitive Type Streams in Java 8
Java Stream Filter with Lambda Expression
Servlet 3 Async Support with Spring MVC and Spring Security
Inheritance with Jackson
Multipart Upload with HttpClient 4
Phương thức forEach() trong java 8
Setting Up Swagger 2 with a Spring REST API
An Intro to Spring Cloud Zookeeper
Java Program to Implement Heap
Convert String to Byte Array and Reverse in Java
Java Program to Implement wheel Sieve to Generate Prime Numbers Between Given Range
Custom Cascading in Spring Data MongoDB
Java Program to implement Bit Matrix
Life Cycle of a Thread in Java
Loại bỏ các phần tử trùng trong một ArrayList như thế nào trong Java 8?
Java Program to Implement Sorting of Less than 100 Numbers in O(n) Complexity
Java Program to Find Nearest Neighbor for Static Data Set
Java Program to Implement Unrolled Linked List
Java Program to Perform Deletion in a BST
Java Program to Describe the Representation of Graph using Incidence List
Java Program to Find Minimum Number of Edges to Cut to make the Graph Disconnected
Send email with authentication
Java Program to Find MST (Minimum Spanning Tree) using Kruskal’s Algorithm
Java Program to Implement Ternary Heap
Spring Security Login Page with React
Removing Elements from Java Collections
Java Program to Perform Postorder Recursive Traversal of a Given Binary Tree