answersLogoWhite

0

How do you write a program in Java to multiply two matrix?

Updated: 8/16/2019
User Avatar

Wiki User

13y ago

Best Answer

class Array58

{

public static void main(String[] args)

{

int i,j,k;

int [][] a={{1,2,3},{4,5,6},{7,8,9}};

int [][] b={{9,8,7},{6,5,4},{3,2,1}};

int [][]c=new int[3][3];

for (i=0;i<a.length;i++)

{

for (j=0;j<a[i].length;j++)

{

System.out.print(a[i][j]+" ");

}

System.out.println(" ");

}

System.out.println(" ");

for (i=0;i<b.length;i++ )

{

for (j=0;j<b[i].length;j++)

{

System.out.print(b[i][j]+" ");

}

System.out.println(" ");

}

System.out.println(" ");

for(i=0;i<a.length;i++)

{

for(j=0;j<b.length;j++)

{

c[i][j]=0;

for(k=0;k<a.length;k++)

{

c[i][j]+=a[i][k]*b[k][j];

}

System.out.print(c[i][j]+" ");

}

System.out.println(" ");

}

}

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program in Java to multiply two matrix?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a java program to find the ad joint of a matrix?

bgfygfrhjyuyhh


How do you write a java program to find the transpose of the matrix for the given elements?

You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.


Can we add website link when we write java program?

yes ,i can add the website link in java program when we write.


How do you write a java program to find the tax on the item and the item's total cost?

You simply multiply the tax rate with the item's original cost and divide by hundred, to get the tax. Then you add that to the original cost, to get the total cost. In Java you use + to add, * to multiply, and / to divide.


Write a c program Fibonacci series using for loop in java?

Exactly what do you mean by 'C program in Java'


What is javadoc?

write a java program to display "Welcome Java" and list its execution steps.


How write new line program in java?

\n


How do you write a java program for finding multiligual languages?

You can use Java's built-in functions to write a code that will find multilingual languages.


How java is 100 percent Internet based?

It isn't. It can also be used to write desktop applications. Java does have many options to program for the Internet, but that is not the only possibility.It isn't. It can also be used to write desktop applications. Java does have many options to program for the Internet, but that is not the only possibility.It isn't. It can also be used to write desktop applications. Java does have many options to program for the Internet, but that is not the only possibility.It isn't. It can also be used to write desktop applications. Java does have many options to program for the Internet, but that is not the only possibility.


Write a java code to draw a circle inside in an ellipse?

write a program draw circle and ellipse by using oval methods in java


How do you write algorithms of java programs?

Write a program that graphically demonstrates the shortest path algorithm


How do you write a java program to find the square root of a number?

You can use the Math.sqrt() method.