# Matrix multiplication

Supriya Kurian
Matrix multiplication
3 Answer(s)      6 years and 8 months ago
Posted in : Java Beginners

program to read the elements of the given two matrices of order n*n and to perform the matrix multiplication.

December 10, 2010 at 1:11 PM

Hi Friend,

Try the following code:

```import java.util.*;
class MatrixMultiplication{

public static void main(String[] args){
Scanner input = new Scanner(System.in);
int[][] A = new int[3][3];
int[][] B = new int[3][3];
int[][] C = new int[3][3];
System.out.println("Enter elements for matrix A : ");
for (int i=0 ; i < A.length ; i++)
for  (int j=0 ; j < A[i].length ; j++){
A[i][j] = input.nextInt();
}
System.out.println("Enter elements for matrix B : ");
for (int i=0 ; i < B.length ; i++)
for  (int j=0 ; j < B[i].length ; j++){
B[i][j] = input.nextInt();
}
System.out.println("Matrix A: ");
for (int i=0 ; i < A.length ; i++){
System.out.println();
for  (int j=0 ; j < A[i].length ; j++){
System.out.print(A[i][j]+" ");
}
}
System.out.println();
System.out.println();
System.out.println("Matrix B: ");
for (int i=0 ; i < B.length ; i++){
System.out.println();
for  (int j=0 ; j < B[i].length ; j++){
System.out.print(B[i][j]+" ");
}
}
System.out.println();
System.out.println();
System.out.println("Result is: ");
System.out.println();

for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
C[i][j]+=A[i][k]*B[k][j];
}
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(+C[i][j]+" ");
}
System.out.println();
}
}
}
```

Thanks

December 10, 2010 at 1:12 PM

Hi Friend,

Try the following code:

```import java.util.*;
class MatrixMultiplication{

public static void main(String[] args){
Scanner input = new Scanner(System.in);
int[][] A = new int[3][3];
int[][] B = new int[3][3];
int[][] C = new int[3][3];
System.out.println("Enter elements for matrix A : ");
for (int i=0 ; i < A.length ; i++)
for  (int j=0 ; j < A[i].length ; j++){
A[i][j] = input.nextInt();
}
System.out.println("Enter elements for matrix B : ");
for (int i=0 ; i < B.length ; i++)
for  (int j=0 ; j < B[i].length ; j++){
B[i][j] = input.nextInt();
}
System.out.println("Matrix A: ");
for (int i=0 ; i < A.length ; i++){
System.out.println();
for  (int j=0 ; j < A[i].length ; j++){
System.out.print(A[i][j]+" ");
}
}
System.out.println();
System.out.println();
System.out.println("Matrix B: ");
for (int i=0 ; i < B.length ; i++){
System.out.println();
for  (int j=0 ; j < B[i].length ; j++){
System.out.print(B[i][j]+" ");
}
}
System.out.println();
System.out.println();
System.out.println("Result is: ");
System.out.println();

for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
C[i][j]+=A[i][k]*B[k][j];
}
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(+C[i][j]+" ");
}
System.out.println();
}
}
}
```

Thanks

July 7, 2011 at 10:11 PM

```import java.util.*;
import java.io.*;
import java.math.*;
class u1
{
public static void main(String[] args)throws IOException
{
System.out.println("Enter Square matrix size");
int u1[][]=new int[u][f];
int f1[][]=new int[u][f];
int uf[][]=new int[u][f];
System.out.println("Enter 1'st matrix values");
for(int i=0;i<u;i++)
{
for(int j=0;j<f;j++)
{
}
}
System.out.println("Enter 2'nd matrix values");
for(int i=0;i<u;i++)
{
for(int j=0;j<f;j++)
{
}
}
System.out.println("Matrix A is:");
for(int i=0;i<u;i++)
{
for(int j=0;j<f;j++)
{
System.out.print("  "+u1[i][j]);
}
System.out.println("");
System.out.println("");
}
System.out.println("");
System.out.println("Matrix B is:");
for(int i=0;i<u;i++)
{
for(int j=0;j<f;j++)
{
System.out.print("  "+f1[i][j]);
}
System.out.println("");
System.out.println("");
}
System.out.println("");
System.out.println("Done by [email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */");
System.out.println("Multiplication of Matrix is:");
for(int i=0;i<u;i++)
{
for(int j=0;j<f;j++)
{
for(int k=0;k<f;k++)
{
uf[i][j]+=u1[i][k]*f1[k][j];
}
}
}

for(int i=0;i<u;i++)
{
for(int j=0;j<f;j++)
{
System.out.print("  "+uf[i][j]);
}
System.out.println("");
System.out.println("");
}
}
}
```

Matrix multiplication
Matrix multiplication  program to read the elements of the given two matrices of order n*n and to perform the matrix multiplication
Parallel multiplication matrix in java
Parallel multiplication matrix in java  hello dear I need parallel multiply matrix in java algorithm to account speed up and efficiency great wishes
parallel dense matrix multiplication
using dense parallel matrix multiplication. I request you to kindly provide me a code for Parallel Matrix multiplication on distributed systems using Java...parallel dense matrix multiplication  hi friends, i am a final year
code for multiplication of matrix in java using methods
code for multiplication of matrix in java using methods  code for multiplication of matrix in java using methods
Matrix Multiplication in Java
Matrix Multiplication in Java In this Java tutorial we will demonstrate you 'Matrix Multiplication in Java' with the help of a simple example from which you can easily learn how to write a matrix multiplication program in Java
Matrix multiplication in java
Matrix multiplication in java In this section we will learn about multiplication of two matrices. In java this is a simple program to multiply two matrices... for the second matrix q = in.nextInt(); // q holding
Multiplication of two Matrix
Multiplication of Two Matrix   ... that teaches you the method to multiply two matrix. We are going to make a simple program that will multiply two matrix. Now to make this program run, you need
Multiplication of two Matrix
Multiplication of two Matrix    ... for multiplying two matrix to each other. Here providing you Java source code... program that will multiply two matrix. Two dimensional array represents
multiplication
multiplication  multiplication of two number numbers entered by user minimum 100digits using GUI   Java Multiplication of two 100 digits number import java.awt.*; import java.math.*; import javax.swing.*; import
multiplication
multiplication  multiplication of two number numbers entered by user minimum 100digits using GUI   Java Multiplication of two 100 digits number import java.awt.*; import java.math.*; import javax.swing.*; import
Java Matrix Multiplication Example
Java Matrix Multiplication Example In this tutorial, you will learn how... the multiplication of two matrices of any order. In the given program, firstly we have... and then accept the matrix elements as array elements. We have declared two
Java, matrix
"); System.out.println("3. Multiplication Of Matrix"); System.out.println("4. Exit"); boolean quit... of switch statement perform operations addition, subtraction and multiplication of matrix.   Hello Friend, Try this: import java.util.*; class
matrix substraction
matrix substraction  hai
matrix substraction
matrix substraction  hai
Multiplication table
Design and develop Multiplication table in Net beans  Design and develop a program that will print a multiplication table. The program should: Ask the user for ending number than it must Display that particular multiplication
Multiplication table
Multiplication table Net Beans  Using Net beans Design and develop... for ending number than Display that particular multiplication table   import java.util.Scanner; class Multiplication { public static void main
Multiplication table
Multiplication table  Using Net beans Design and develop a program... number than Display that particular multiplication table   import java.util.Scanner; class Multiplication { public static void main(String args
column matrix
column matrix  columan wise total matrix
column matrix
column matrix  columan wise total matrix
transpose matrix
integers into the matrix and print the transpose of it. for this program u r given answer but if i entered 2 by 3 matrix it will not give answer ple check it once
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
transpose of matrix
transpose of matrix  write a program in java to declare a square matrices 'A' or order n which is less than 20.allow in user to input only positive integers into the matrix and print the transpose
matrix determination in java
matrix determination in java  hai