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:
Spring Boot - Tracing Micro Service Logs
Java Program to Implement LinkedBlockingDeque API
Adding a Newline Character to a String in Java
How to Store Duplicate Keys in a Map in Java?
Java – Rename or Move a File
Java Program to implement Dynamic Array
Lớp TreeMap trong Java
Spring Data MongoDB Transactions
The Java 8 Stream API Tutorial
Spring Boot - Build Systems
Spring Webflux and CORS
Merging Streams in Java
Java Program to Find the Peak Element of an Array O(n) time (Naive Method)
Handling URL Encoded Form Data in Spring REST
Giới thiệu Google Guice – Injection, Scope
Java Program to implement Array Deque
Jackson – Change Name of Field
Sắp xếp trong Java 8
Guide to Guava Table
Jackson Unmarshalling JSON with Unknown Properties
Java Program to Implement Stack using Linked List
Java Program to Implement a Binary Search Tree using Linked Lists
Java Program to Implement CopyOnWriteArraySet API
So sánh Array và ArrayList trong Java
Java Program to Check if a Given Graph Contain Hamiltonian Cycle or Not
Life Cycle of a Thread in Java
Java 8 Predicate Chain
Java Program to Perform the Sorting Using Counting Sort
Introduction to Spring Data REST
A Guide to JUnit 5
Java Program to Implement Splay Tree
Apache Commons Collections OrderedMap