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 MVC + Thymeleaf 3.0: New Features
Java Program to Check Whether an Input Binary Tree is the Sub Tree of the Binary Tree
A Custom Media Type for a Spring REST API
Spring Boot - Quick Start
Thao tác với tập tin và thư mục trong Java
Java Program to Implement Euler Circuit Problem
A Guide to TreeMap in Java
Spring @RequestParam Annotation
JUnit 5 @Test Annotation
So sánh HashMap và Hashtable trong Java
Java Program to Solve TSP Using Minimum Spanning Trees
Java Program to Describe the Representation of Graph using Incidence Matrix
Count Occurrences of a Char in a String
Java Program to Perform Postorder Non-Recursive Traversal of a Given Binary Tree
Wrapper Classes in Java
HttpAsyncClient Tutorial
HttpClient 4 Cookbook
Java – Try with Resources
Java – Delete a File
ETags for REST with Spring
Java Program to Perform Insertion in a 2 Dimension K-D Tree
Converting a Stack Trace to a String in Java
Convert String to Byte Array and Reverse in Java
Guide to CopyOnWriteArrayList
Spring Cloud AWS – RDS
Spring @RequestMapping New Shortcut Annotations
Quick Guide to Spring Bean Scopes
Giới thiệu thư viện Apache Commons Chain
Java – Get Random Item/Element From a List
Java Program to Implement Counting Sort
Java Program to Implement ConcurrentHashMap API
Introduction to Java Serialization