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:
ExecutorService – Waiting for Threads to Finish
Java Program to Compute the Volume of a Tetrahedron Using Determinants
Java Program to Implement Bellman-Ford Algorithm
Java Program to Generate a Sequence of N Characters for a Given Specific Case
HTTP Authentification and CGI/Servlet
Getting Started with Custom Deserialization in Jackson
Java Program to implement Sparse Vector
Java Program to Implement LinkedHashSet API
@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll
Performance Difference Between save() and saveAll() in Spring Data
The Difference Between Collection.stream().forEach() and Collection.forEach()
Build a REST API with Spring and Java Config
Java Program to Check Cycle in a Graph using Graph traversal
Custom HTTP Header with the HttpClient
Java Program to Check Whether an Undirected Graph Contains a Eulerian Path
Java Program to Check whether Graph is a Bipartite using DFS
Uploading MultipartFile with Spring RestTemplate
Java Program to Implement Heap’s Algorithm for Permutation of N Numbers
Java Program to Implement Warshall Algorithm
LinkedHashSet trong java
Java Program to Check whether Directed Graph is Connected using DFS
Quick Guide to the Java StringTokenizer
Một số ký tự đặc biệt trong Java
Java Program to Check whether Graph is a Bipartite using BFS
So sánh HashMap và Hashtable trong Java
Java 14 Record Keyword
Removing all Nulls from a List in Java
Java Program to Implement Fibonacci Heap
Guide to the Volatile Keyword in Java
Converting between an Array and a List in Java
How to Change the Default Port in Spring Boot
Java Program to Generate a Random Subset by Coin Flipping