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:

Spring MVC + Thymeleaf 3.0: New Features
Optional trong Java 8
Java Program to Implement the Schonhage-Strassen Algorithm for Multiplication of Two Numbers
Tạo chương trình Java đầu tiên sử dụng Eclipse
Spring Security 5 – OAuth2 Login
Rest Web service: Filter và Interceptor với Jersey 2.x (P1)
Java Optional as Return Type
Send email with SMTPS (eg. Google GMail)
Configure a Spring Boot Web Application
Spring Data MongoDB – Indexes, Annotations and Converters
Spring 5 Functional Bean Registration
So sánh HashMap và Hashtable trong Java
Spring Cloud – Tracing Services with Zipkin
Java Program to Implement Max-Flow Min-Cut Theorem
Java Program to Perform Preorder Non-Recursive Traversal of a Given Binary Tree
Java 8 Stream API Analogies in Kotlin
Java Program to Implement Randomized Binary Search Tree
Java Web Services – Jersey JAX-RS – REST và sử dụng REST API testing tools với Postman
Injecting Prototype Beans into a Singleton Instance in Spring
Java Program to Implement Word Wrap Problem
Spring Cloud AWS – Messaging Support
Concatenating Strings In Java
Java Program to Implement Doubly Linked List
Kết hợp Java Reflection và Java Annotations
Lập trình đa luồng với Callable và Future trong Java
Java Program to Perform Optimal Paranthesization Using Dynamic Programming
Introduction to Spring Data JPA
Add Multiple Items to an Java ArrayList
Java Program to Implement ConcurrentSkipListMap API
The Thread.join() Method in Java
Java Program to Implement the Vigenere Cypher
Java toString() Method