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 Self Balancing Binary Search Tree
Java Program to Implement Variable length array
Get the workstation name or IP
Connect through a Proxy
Comparing Arrays in Java
Quick Guide to java.lang.System
Java Program to Implement Borwein Algorithm
Spring MVC + Thymeleaf 3.0: New Features
Java Program to Perform Partial Key Search in a K-D Tree
Java Program to Implement CountMinSketch
Java Program for Douglas-Peucker Algorithm Implementation
Java Program to Find the Number of Ways to Write a Number as the Sum of Numbers Smaller than Itself
Java Convenience Factory Methods for Collections
XML Serialization and Deserialization with Jackson
Spring AMQP in Reactive Applications
Java Program to Implement ConcurrentLinkedQueue API
Java Program to Apply DFS to Perform the Topological Sorting of a Directed Acyclic Graph
Java Program to Represent Graph Using Adjacency Matrix
Java Program to Implement Word Wrap Problem
Java 8 Streams peek() API
Một số từ khóa trong Java
Spring Autowiring of Generic Types
Java Program to Implement Extended Euclid Algorithm
Java Program to Implement Quick Hull Algorithm to Find Convex Hull
Tìm hiểu về xác thực và phân quyền trong ứng dụng
Marker Interface trong Java
Java Program to Implement Binomial Tree
Java Program to Find Path Between Two Nodes in a Graph
Tính đa hình (Polymorphism) trong Java
Annotation trong Java 8
Java Program to Find Nearest Neighbor for Dynamic Data Set
Java Program to Implement Triply Linked List