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 find the maximum subarray sum using Binary Search approach
Java Program to Solve Knapsack Problem Using Dynamic Programming
Join and Split Arrays and Collections in Java
So sánh ArrayList và Vector trong Java
Map Serialization and Deserialization with Jackson
TreeSet và sử dụng Comparable, Comparator trong java
Supplier trong Java 8
Implementing a Runnable vs Extending a Thread
New Features in Java 8
Guava – Join and Split Collections
Java Program to Find the Shortest Path Between Two Vertices Using Dijkstra’s Algorithm
Java Program to Apply DFS to Perform the Topological Sorting of a Directed Acyclic Graph
Java 14 Record Keyword
HTTP Authentification and CGI/Servlet
Lập trình đa luồng với CompletableFuture trong Java 8
Hướng dẫn sử dụng Java Annotation
Abstract class và Interface trong Java
@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll
Properties with Spring and Spring Boot
Java Program to Find the Edge Connectivity of a Graph
Java Program to Implement LinkedBlockingQueue API
Spring RequestMapping
Java Program to Implement Attribute API
Spring Boot Tutorial – Bootstrap a Simple Application
Java Program to Implement Horner Algorithm
How to Count Duplicate Elements in Arraylist
How to Get a Name of a Method Being Executed?
Spring Cloud AWS – RDS
Mảng (Array) trong Java
Java Program to Implement Binary Heap
Jackson Exceptions – Problems and Solutions
The HttpMediaTypeNotAcceptableException in Spring MVC