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 Solve Set Cover Problem assuming at max 2 Elements in a Subset
Giới thiệu Aspect Oriented Programming (AOP)
Java Program to Implement Segment Tree
Java Program to Implement Stack using Two Queues
Java Program to Emulate N Dice Roller
Default Password Encoder in Spring Security 5
XML-Based Injection in Spring
Java Program to Implement Bucket Sort
Ép kiểu trong Java (Type casting)
Java Program to Implement Sieve Of Atkin
Introduction to Using FreeMarker in Spring MVC
Instance Profile Credentials using Spring Cloud
Create a Custom Auto-Configuration with Spring Boot
Java 14 Record Keyword
Retrieve User Information in Spring Security
Spring Boot - Code Structure
Converting Java Date to OffsetDateTime
Java Program to Check if a Matrix is Invertible
Java – File to Reader
Java Program to Implement CountMinSketch
So sánh HashMap và HashSet trong Java
Java Program to Implement Fenwick Tree
Java Program to Implement Max-Flow Min-Cut Theorem
Spring MVC Tutorial
Java Program to Implement Strassen Algorithm
What is a POJO Class?
Java Program to Implement Hash Tables with Quadratic Probing
Guide to the Volatile Keyword in Java
Spring Cloud – Securing Services
Send an email with an attachment
Lập trình đa luồng với CompletableFuture trong Java 8
Java Program to Implement Sorted List