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 Hash Tables with Linear Probing
Using a Mutex Object in Java
Java Program to Implement Dijkstra’s Algorithm using Priority Queue
Lập trình đa luồng trong Java (Java Multi-threading)
Java Program to Implement Iterative Deepening
How to Get All Dates Between Two Dates?
Custom Thread Pools In Java 8 Parallel Streams
Java Program to Check Cycle in a Graph using Topological Sort
Java Program to Perform Optimal Paranthesization Using Dynamic Programming
Java Program to Construct a Random Graph by the Method of Random Edge Selection
Login For a Spring Web App – Error Handling and Localization
Converting Strings to Enums in Java
Generating Random Numbers in a Range in Java
Custom Exception trong Java
Java Program to Implement Ternary Tree
Tìm hiểu cơ chế Lazy Evaluation của Stream trong Java 8
Java Program to Implement Queue
Rate Limiting in Spring Cloud Netflix Zuul
Spring Boot - Building RESTful Web Services
Spring Boot - Code Structure
Java Program to Implement Sparse Array
Vector trong Java
Deploy a Spring Boot WAR into a Tomcat Server
Java – String to Reader
Java Program to Implement Treap
Từ khóa this và super trong Java
Java Program to Find Maximum Element in an Array using Binary Search
Custom Thread Pools In Java 8 Parallel Streams
Java Program to Implement Euclid GCD Algorithm
Java Program to Implement RenderingHints API
Java Program to Implement Sorted Array
Comparing Strings in Java