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 Hamiltonian Cycle in an UnWeighted Graph
A Guide to Spring Cloud Netflix – Hystrix
Java Program to Implement Coppersmith Freivald’s Algorithm
Java Program to Implement Singly Linked List
Java Program to Apply Above-Below-on Test to Find the Position of a Point with respect to a Line
Java Program to Implement Sieve Of Atkin
Spring JDBC
Lập trình mạng với java
Java InputStream to Byte Array and ByteBuffer
Java Program to Check Cycle in a Graph using Graph traversal
The Registration API becomes RESTful
Java Program to Implement the linear congruential generator for Pseudo Random Number Generation
Java Program to Implement Bit Array
A Guide to the ResourceBundle
Java Program to Solve TSP Using Minimum Spanning Trees
Giới thiệu Design Patterns
Semaphore trong Java
Receive email using IMAP
Java Program to Implement Hopcroft Algorithm
How to Read HTTP Headers in Spring REST Controllers
Java Program to Implement LinkedBlockingQueue API
An Introduction to ThreadLocal in Java
Interface trong Java 8 – Default method và Static method
Remove All Occurrences of a Specific Value from a List
Java Program to Implement Radix Sort
Properties with Spring and Spring Boot
Filtering a Stream of Optionals in Java
A Guide to the Java ExecutorService
Spring Boot - Cloud Configuration Client
Java Program to Construct an Expression Tree for an Prefix Expression
Comparing Dates in Java
Spring Boot - Tomcat Deployment