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:
Generate Spring Boot REST Client with Swagger
Java Program to Implement Fisher-Yates Algorithm for Array Shuffling
Java Program to Implement Gift Wrapping Algorithm in Two Dimensions
Spring Boot - Exception Handling
Guava CharMatcher
Java Program to Implement Radix Sort
Java Program to Implement the Checksum Method for Small String Messages and Detect
Sao chép các phần tử của một mảng sang mảng khác như thế nào?
Java Program to Perform Searching in a 2-Dimension K-D Tree
Vector trong Java
Collection trong java
Guide To CompletableFuture
A Guide to Spring Cloud Netflix – Hystrix
Java Program to Implement JobStateReasons API
Java Program for Douglas-Peucker Algorithm Implementation
Hướng dẫn Java Design Pattern – Builder
Hướng dẫn Java Design Pattern – Adapter
Creating a Web Application with Spring 5
Check if a String is a Palindrome in Java
A Guide to LinkedHashMap in Java
Java Program to Implement CopyOnWriteArraySet API
Java 8 Stream API Analogies in Kotlin
Một số từ khóa trong Java
HttpAsyncClient Tutorial
Java Program to Sort an Array of 10 Elements Using Heap Sort Algorithm
Java InputStream to String
Java Program to Implement Sorted Vector
Check If a String Is Numeric in Java
Java Program to Perform Preorder Recursive Traversal of a Given Binary Tree
Java Program to Implement Bellman-Ford Algorithm
Prevent Cross-Site Scripting (XSS) in a Spring Application
Java Program to Implement Johnson’s Algorithm