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 Implement Fibonacci Heap
Merging Two Maps with Java 8
Java Program to Solve Set Cover Problem assuming at max 2 Elements in a Subset
File Upload with Spring MVC
Java Program to Perform the Unique Factorization of a Given Number
Working with Network Interfaces in Java
Java Program to Implement Bubble Sort
Spring Boot - Rest Controller Unit Test
Java Program to Implement Hash Tables with Linear Probing
Quản lý bộ nhớ trong Java với Heap Space vs Stack
Java Program to Find the Peak Element of an Array O(n) time (Naive Method)
Rest Web service: Filter và Interceptor với Jersey 2.x (P2)
Java Program to Implement the Monoalphabetic Cypher
Primitive Type Streams in Java 8
REST Pagination in Spring
Java Byte Array to InputStream
Một số từ khóa trong Java
Find the Registered Spring Security Filters
Check if there is mail waiting
Limiting Query Results with JPA and Spring Data JPA
Java 8 – Powerful Comparison with Lambdas
Java Program to Create a Minimal Set of All Edges Whose Addition will Convert it to a Strongly Conne...
SOAP Web service: Upload và Download file sử dụng MTOM trong JAX-WS
REST Web service: HTTP Status Code và xử lý ngoại lệ RESTful web service với Jersey 2.x
Removing Elements from Java Collections
Java Program to Implement Min Hash
Java Program to Implement Sorted Array
Guide to the Java ArrayList
Java Program to Implement Bit Array
Quick Guide to java.lang.System
Show Hibernate/JPA SQL Statements from Spring Boot
Giới thiệu Google Guice – Injection, Scope