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:

Rest Web service: Filter và Interceptor với Jersey 2.x (P1)
Java Program to Implement Vector API
Custom JUnit 4 Test Runners
Java Program to Implement Queue
Java Program to Generate All Subsets of a Given Set in the Lexico Graphic Order
Spring Boot: Customize the Jackson ObjectMapper
Tránh lỗi NullPointerException trong Java như thế nào?
LinkedHashSet trong Java hoạt động như thế nào?
Converting Iterator to List
Guide to Java 8’s Collectors
Entity To DTO Conversion for a Spring REST API
Java Program to Implement the Alexander Bogomolny’s UnOrdered Permutation Algorithm for Elements Fro...
Java Program to Solve a Matching Problem for a Given Specific Case
Convert char to String in Java
Loại bỏ các phần tử trùng trong một ArrayList như thế nào trong Java 8?
Guide to BufferedReader
The DAO with Spring and Hibernate
How to Read a Large File Efficiently with Java
Model, ModelMap, and ModelAndView in Spring MVC
Compact Strings in Java 9
HttpClient Basic Authentication
Tránh lỗi NullPointerException trong Java như thế nào?
Java Program to Implement Meldable Heap
Java Program to Permute All Letters of an Input String
Configuring a DataSource Programmatically in Spring Boot
A Guide to the finalize Method in Java
Java Program to Solve Tower of Hanoi Problem using Stacks
Java Program to Implement the One Time Pad Algorithm
Java Program to Perform Postorder Recursive Traversal of a Given Binary Tree
Java Program to Find Nearest Neighbor for Static Data Set
Java Program to Implement Quick Hull Algorithm to Find Convex Hull
Interface trong Java 8 – Default method và Static method