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:
Spring Boot - CORS Support
Converting String to Stream of chars
Spring MVC and the @ModelAttribute Annotation
Using Spring @ResponseStatus to Set HTTP Status Code
Java Program to Implement Variable length array
Lớp Arrarys trong Java (Arrays Utility Class)
Java 8 Streams peek() API
Java Program to Implement PrinterStateReasons API
Java program to Implement Tree Set
Java Program to Perform Finite State Automaton based Search
Creating Docker Images with Spring Boot
How to Manually Authenticate User with Spring Security
How to Add a Single Element to a Stream
Spring Boot - Bootstrapping
Encode/Decode to/from Base64
Convert char to String in Java
Spring Boot - Admin Client
Introduction to Thread Pools in Java
Configure a Spring Boot Web Application
Java Program to Check Cycle in a Graph using Topological Sort
A Guide to the finalize Method in Java
Getting Started with Custom Deserialization in Jackson
Versioning a REST API
Spring Boot - Quick Start
How to Get All Spring-Managed Beans?
Spring Boot - Tomcat Port Number
Tạo chương trình Java đầu tiên sử dụng Eclipse
Spring Boot - Hystrix
Java 8 StringJoiner
Java Program to Implement Circular Singly Linked List
Immutable ArrayList in Java
Giới thiệu thư viện Apache Commons Chain