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:
Testing in Spring Boot
Spring Boot - Apache Kafka
Spring Security Custom AuthenticationFailureHandler
How to Get All Dates Between Two Dates?
Implementing a Runnable vs Extending a Thread
Multi Dimensional ArrayList in Java
Java Program to Implement Sparse Array
Java InputStream to Byte Array and ByteBuffer
REST Web service: HTTP Status Code và xử lý ngoại lệ RESTful web service với Jersey 2.x
Java Program to Implement Ternary Tree
Default Password Encoder in Spring Security 5
Examine the internal DNS cache
Java Program to Implement Gauss Jordan Elimination
Quick Intro to Spring Cloud Configuration
A Guide to Java HashMap
Introduction to Spring Cloud Rest Client with Netflix Ribbon
Overflow and Underflow in Java
Entity To DTO Conversion for a Spring REST API
Java Program to Find Minimum Element in an Array using Linear Search
Java Program to Implement EnumMap API
Java TreeMap vs HashMap
Spring Boot - Google OAuth2 Sign-In
Hướng dẫn sử dụng Java Generics
Generate Spring Boot REST Client with Swagger
Java Program to Implement Rolling Hash
HttpClient with SSL
Java Program to find the maximum subarray sum O(n^2) time(naive method)
How to Replace Many if Statements in Java
Converting a Stack Trace to a String in Java
Java Program to Implement LinkedTransferQueue API
Java Program to Find SSSP (Single Source Shortest Path) in DAG (Directed Acyclic Graphs)
Rate Limiting in Spring Cloud Netflix Zuul