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 the number of occurrences of a given number using Binary Search approach
Java Program to Emulate N Dice Roller
Java Program to Implement Kosaraju Algorithm
Guide to Spring Cloud Kubernetes
Java Program to Implement the Edmond’s Algorithm for Maximum Cardinality Matching
Spring Boot Annotations
Các nguyên lý thiết kế hướng đối tượng – SOLID
Java Program to Implement Circular Singly Linked List
Configure a RestTemplate with RestTemplateBuilder
Java Program to Implement Horner Algorithm
Spring Boot - Google OAuth2 Sign-In
Hướng dẫn Java Design Pattern – Decorator
Tính đa hình (Polymorphism) trong Java
Java Program to Implement Efficient O(log n) Fibonacci generator
Java CyclicBarrier vs CountDownLatch
Java Program to Implement First Fit Decreasing for 1-D Objects and M Bins
Send an email with an attachment
Thao tác với tập tin và thư mục trong Java
How to Get the Last Element of a Stream in Java?
Java Optional as Return Type
Wiring in Spring: @Autowired, @Resource and @Inject
Java – Reader to Byte Array
Spring Boot - Sending Email
Spring Boot - Runners
Request a Delivery / Read Receipt in Javamail
Giới thiệu luồng vào ra (I/O) trong Java
Runnable vs. Callable in Java
Spring Boot with Multiple SQL Import Files
Hướng dẫn Java Design Pattern – Proxy
Java Program to Implement the One Time Pad Algorithm
Assertions in JUnit 4 and JUnit 5
HttpClient 4 – Follow Redirects for POST