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:
Hướng dẫn Java Design Pattern – Abstract Factory
Explain about URL and HTTPS protocol
JUnit 5 @Test Annotation
Java Program to Perform Searching in a 2-Dimension K-D Tree
Java Program to Implement Strassen Algorithm
So sánh Array và ArrayList trong Java
A Guide to Java HashMap
Automatic Property Expansion with Spring Boot
Spring REST API + OAuth2 + Angular
Spring WebClient Filters
Exploring the New Spring Cloud Gateway
Java – Get Random Item/Element From a List
Java Program to Check the Connectivity of Graph Using BFS
Java Program to implement Associate Array
Hướng dẫn Java Design Pattern – Strategy
Java Program to Solve Knapsack Problem Using Dynamic Programming
Lập trình đa luồng với CompletableFuture trong Java 8
Hashing a Password in Java
A Guide to System.exit()
Spring Boot: Customize Whitelabel Error Page
Java InputStream to Byte Array and ByteBuffer
Spring Security Remember Me
Giới thiệu JDBC Connection Pool
Java Program to Implement Borwein Algorithm
Spring Security Form Login
Using Custom Banners in Spring Boot
Java Program to Implement Bellman-Ford Algorithm
4 tính chất của lập trình hướng đối tượng trong Java
Removing all duplicates from a List in Java
Functional Interfaces in Java 8
Java Program to Check whether Graph is a Bipartite using DFS
Java Program to Check if a Given Set of Three Points Lie on a Single Line or Not