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 kth Largest Element in a Sequence
Simplify the DAO with Spring and Java Generics
Java Program for Topological Sorting in Graphs
Apache Tiles Integration with Spring MVC
How to Read HTTP Headers in Spring REST Controllers
HashSet trong Java hoạt động như thế nào?
Java Program to Find the Vertex Connectivity of a Graph
Java 8 and Infinite Streams
Guide to ThreadLocalRandom in Java
Spring RestTemplate Error Handling
Java program to Implement Tree Set
Difference Between Wait and Sleep in Java
Java Program to Perform Inorder Non-Recursive Traversal of a Given Binary Tree
Pagination and Sorting using Spring Data JPA
Java Program to Compute the Volume of a Tetrahedron Using Determinants
Java Program to Implement Find all Forward Edges in a Graph
Java Program to Perform Cryptography Using Transposition Technique
An Intro to Spring Cloud Task
Dockerizing a Spring Boot Application
Java – InputStream to Reader
Get the workstation name or IP
Cachable Static Assets with Spring MVC
Java Program to Implement PriorityQueue API
Guide to the Volatile Keyword in Java
Deque và ArrayDeque trong Java
Introduction to Spring MVC HandlerInterceptor
Logging a Reactive Sequence
Java Map With Case-Insensitive Keys
Java Program to Implement Attribute API
Java Collections Interview Questions
Java Program to Generate Date Between Given Range
Java Program to Implement Fermat Factorization Algorithm