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:
Reactive WebSockets with Spring 5
Easy Ways to Write a Java InputStream to an OutputStream
Spring Boot - Introduction
Mệnh đề Switch-case trong java
Spring AMQP in Reactive Applications
Loại bỏ các phần tử trùng trong một ArrayList như thế nào?
Spring Security Registration – Resend Verification Email
Serve Static Resources with Spring
Feign – Tạo ứng dụng Java RESTful Client
Java Program to Implement Hash Tables with Linear Probing
Java Program to Find Nearest Neighbor for Dynamic Data Set
Java Program to Implement K Way Merge Algorithm
REST Web service: Tạo ứng dụng Java RESTful Client với Jersey Client 2.x
Java Program to Generate a Sequence of N Characters for a Given Specific Case
So sánh Array và ArrayList trong Java
DynamoDB in a Spring Boot Application Using Spring Data
Java Program to implement Associate Array
Jackson – Unmarshall to Collection/Array
Java Program to Implement Gale Shapley Algorithm
An Intro to Spring Cloud Vault
Giới thiệu Design Patterns
Java Program to Implement the linear congruential generator for Pseudo Random Number Generation
Display Auto-Configuration Report in Spring Boot
Notify User of Login From New Device or Location
Các chương trình minh họa sử dụng Cấu trúc điều khiển trong Java
Spring Boot With H2 Database
Spring Boot - Google OAuth2 Sign-In
Spring Autowiring of Generic Types
Prevent Brute Force Authentication Attempts with Spring Security
Java Program to implement Sparse Vector
How to Round a Number to N Decimal Places in Java
Java Program to Implement TreeSet API