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 Test Using DFS Whether a Directed Graph is Weakly Connected or Not
Marker Interface trong Java
Introduction to Spring Security Expressions
Java Program to Implement Dijkstra’s Algorithm using Queue
Spring Security and OpenID Connect
Java Program to Check Cycle in a Graph using Graph traversal
String Joiner trong Java 8
How to Read a File in Java
Removing Elements from Java Collections
Java Program to Implement Slicker Algorithm that avoids Triangulation to Find Area of a Polygon
Java Program to Implement Hash Tables with Linear Probing
Apache Camel with Spring Boot
New Features in Java 15
Jackson vs Gson
Java Program to subtract two large numbers using Linked Lists
Java Program to Remove the Edges in a Given Cyclic Graph such that its Linear Extension can be Found
Hamcrest Collections Cookbook
A Guide to ConcurrentMap
Sắp xếp trong Java 8
Arrays.asList vs new ArrayList(Arrays.asList())
Converting Between a List and a Set in Java
Number Formatting in Java
Java Program to Implement Control Table
Filtering a Stream of Optionals in Java
Convert XML to JSON Using Jackson
Guide to the Java Clock Class
OAuth 2.0 Resource Server With Spring Security 5
Java Program to Implement Gaussian Elimination Algorithm
Loại bỏ các phần tử trùng trong một ArrayList như thế nào?
Spring MVC + Thymeleaf 3.0: New Features
Java – Try with Resources
Java Program to Implement LinkedTransferQueue API