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 Check whether Directed Graph is Connected using DFS
Java Program to Check if any Graph is Possible to be Constructed for a Given Degree Sequence
Java Program to Find the Shortest Path Between Two Vertices Using Dijkstra’s Algorithm
Lớp lồng nhau trong java (Java inner class)
Java Program to Implement Binary Heap
Java Program to Implement Depth-limited Search
Spring Boot - OAuth2 with JWT
Spring Boot - Build Systems
Introduction to Spliterator in Java
Java Program to Implement Dijkstra’s Algorithm using Queue
Guide to java.util.concurrent.BlockingQueue
Hướng dẫn sử dụng Printing Service trong Java
Java Program to Implement Euclid GCD Algorithm
Debug a JavaMail Program
Java Program to Implement the Binary Counting Method to Generate Subsets of a Set
Java Program to Implement Gauss Seidel Method
Handling URL Encoded Form Data in Spring REST
Java Program to Use rand and srand Functions
The Spring @Controller and @RestController Annotations
Spring REST API + OAuth2 + Angular (using the Spring Security OAuth legacy stack)
Map to String Conversion in Java
Quick Guide to Spring MVC with Velocity
The XOR Operator in Java
Iterating over Enum Values in Java
REST Web service: HTTP Status Code và xử lý ngoại lệ RESTful web service với Jersey 2.x
Simple Single Sign-On with Spring Security OAuth2
Introduction to Using Thymeleaf in Spring
Spring Boot With H2 Database
Introduction to Spring Cloud Rest Client with Netflix Ribbon
Java Program to Check if a Point d lies Inside or Outside a Circle Defined by Points a, b, c in a Pl...
Spring Boot Change Context Path
Java Program to implement Priority Queue