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:
Period and Duration in Java
Java – Write a Reader to File
Java Program to Give an Implementation of the Traditional Chinese Postman Problem
Documenting a Spring REST API Using OpenAPI 3.0
Java Program to implement Sparse Vector
Java Program to Implement Wagner and Fisher Algorithm for online String Matching
Spring Data MongoDB Transactions
An Example of Load Balancing with Zuul and Eureka
Java Web Services – Jersey JAX-RS – REST và sử dụng REST API testing tools với Postman
Spring Boot - Hystrix
Guide to Character Encoding
Guide to Java 8 groupingBy Collector
Creating a Custom Starter with Spring Boot
Giới thiệu Swagger – Công cụ document cho RESTfull APIs
Các nguyên lý thiết kế hướng đối tượng – SOLID
Base64 encoding và decoding trong Java 8
Java Program to Implement Hash Tables
JUnit5 @RunWith
Java 8 Collectors toMap
Java Program to Implement Find all Back Edges in a Graph
Simple Single Sign-On with Spring Security OAuth2
Spring Boot Integration Testing with Embedded MongoDB
Java Program to Check whether Directed Graph is Connected using DFS
Java Program to Sort an Array of 10 Elements Using Heap Sort Algorithm
Java Program to Solve Set Cover Problem assuming at max 2 Elements in a Subset
Java Program to Apply DFS to Perform the Topological Sorting of a Directed Acyclic Graph
Introduction to Spring Method Security
Introduction to Spring MVC HandlerInterceptor
Java Program to Implement Multi-Threaded Version of Binary Search Tree
Java Program to Implement Stack
Hướng dẫn Java Design Pattern – Composite
Converting a Stack Trace to a String in Java