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 Implement CopyOnWriteArrayList API
Java Program to Construct K-D Tree for 2 Dimensional Data
Jackson Exceptions – Problems and Solutions
Hướng dẫn Java Design Pattern – Null Object
A Quick JUnit vs TestNG Comparison
Easy Ways to Write a Java InputStream to an OutputStream
Enum trong java
Java Program to Implement TreeMap API
Introduction to the Java ArrayDeque
Lớp Collections trong Java (Collections Utility Class)
Template Engines for Spring
Hướng dẫn Java Design Pattern – Bridge
Java Program to Implement Gift Wrapping Algorithm in Two Dimensions
Java Program to Implement Gale Shapley Algorithm
Java Timer
Từ khóa this và super trong Java
Logging a Reactive Sequence
Class Loaders in Java
Java Program to Implement Shunting Yard Algorithm
Java Program to Implement ArrayList API
Java Program to Permute All Letters of an Input String
Java Program to Represent Graph Using Adjacency List
Spring Boot - Flyway Database
Tính đa hình (Polymorphism) trong Java
Zipping Collections in Java
An Introduction to ThreadLocal in Java
Java Program to Implement Pollard Rho Algorithm
Java 14 Record Keyword
Spring Security Form Login
Most commonly used String methods in Java
Hướng dẫn sử dụng luồng vào ra ký tự trong Java
Java Program to Perform Stooge Sort