answersLogoWhite

0


Best Answer

//Matrix multiplication import java.util.Scanner; public class Matrix

{

public static void main(String args[])

{

Scanner s= new Scanner(System.in);

int i,j,k; System.out.println("enter the value of n"); int n=s.nextInt(); int a[][]=new int[n][n]; int b[][]=new int[n][n]; int c[][]=new int[n][n]; System.out.println("enter the array elements of a:"); for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

a[i][j]=s.nextInt();

}

}//end of a matrix System.out.println("enter the array elements of b:"); for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

b[i][j]=s.nextInt();

}

}//end of b matrix System.out.println("the result matrix is:");

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

for(k=0;k<n;k++)

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

}

} for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

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

}System.out.println();

}

}//end of main

}//end of class

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

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(" ");

}

}

}

Shashi 8010234944

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

import java.util.Scanner; public class Matrix

{

public static void main(String args[])

{

Scanner s= new Scanner(System.in);

int i,j,k; System.out.println("enter the value of n"); int n=s.nextInt(); int a[][]=new int[n][n]; int b[][]=new int[n][n]; int c[][]=new int[n][n]; System.out.println("enter the array elements of a:"); for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

a[i][j]=s.nextInt();

}

}//end of a matrix System.out.println("enter the array elements of b:"); for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

b[i][j]=s.nextInt();

}

}//end of b matrix System.out.println("the result matrix is:");

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

for(k=0;k<n;k++)

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

}

} for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

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

}

}

}//end of main

}//end of class

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

import java.io.*;

public class matrixmul

{

public static void main (String args[])

{

try

{

BufferedReader e = new BufferedReader(new InputStreamReader(System.in));

int m,n;

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

int b[][] = new int[3][3];

int d[][] = new int[3][3];

for ( m = 0 ; m < 3; m++ )

{

for (n = 0; n < 3 ;n++)

{

System.out.println("-- Enter A number in row# "+(m+1)+" & # "+(n+1)+" column --" );

c[m][n] = Integer.parseInt(e.readLine());

}

}

System.out.println(" ----- First Matrix ----");

for ( m = 0 ; m < 3; m++ )

{

for (n = 0; n < 3 ; n++)

{

System.out.print(c[m][n]);

}

System.out.println();

}

for ( m = 0 ; m < 3; m++ )

{

for (n = 0; n < 3 ;n++)

{

System.out.println("-- Enter A number in row# "+(m+1)+" & # "+(n+1)+" column --" );

b[m][n] = Integer.parseInt(e.readLine());

}

}

System.out.println(" ----- Second Matrix ----");

for ( m = 0 ; m < 3; m++ )

{

for (n = 0; n < 3 ; n++)

{

System.out.print(c[m][n]);

}

System.out.println();

}

for ( m = 0 ; m < 3; m++ )

{

for (n = 0; n < 3 ;n++)

{

d[m][n] = d[m][n]+(b[m][n]*c[m][n]);

}

}

System.out.println(" ----- Multiplication of above matrix ----");

for ( m = 0 ; m < 3; m++ )

{

for (n = 0; n < 3 ; n++)

{

System.out.print(" "+d[m][n]);

}

System.out.println();

}

}

catch (Exception e){}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Matrix Add

/* Program MAT_ADD.C
**
** Illustrates how to add two 3X3 matrices.
**
** Peter H. Anderson, Feb 21, '97
*/

#include <stdio.h>

void add_matrices(int a[][3], int b[][3], int result[][3]);
void print_matrix(int a[][3]);

void main(void)
{
int p[3][3] = { {1, 3, -4}, {1, 1, -2}, {-1, -2, 5} };
int q[3][3] = { {8, 3, 0}, {3, 10, 2}, {0, 2, 6} };
int r[3][3];

add_matrices(p, q, r);

printf("\nMatrix 1:\n");
print_matrix(p);

printf("\nMatrix 2:\n");
print_matrix(q);

printf("\nResult:\n");
print_matrix(r);
}

void add_matrices(int a[][3], int b[][3], int result[][3])
{
int i, j;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
result[i][j] = a[i][j] + b[i][j];
}
}
}

void print_matrix(int a[][3])
{
int i, j;
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("%d\t", a[i][j]);
}
printf("\n");
}
}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

import java.io.*;

class mat

{

protected static void main()throws IOException

{

BufferedReader in=new BufferedReader(new InputStreamReader());

int a[][]=new int[10][10];

int b[][]=new int[10][10];

int c[][]=new int[10][10];

for(byte i=0;i<10;i++)

{

for(byte j=0;j<10;j++)

{

System.out.print("Enter the value of a[ "+i+" ][ "+j+"]: ");

a[i][j]=Integer.parseInt(in.readLine());

}

}

for(byte i=0;i<10;i++)

{

for(byte j=0;j<10;j++)

{

System.out.print("Enter the value of b["+i+" ][ "+j+" ]: ");

b[i][j]=Integer.parseInt(in.readLine());

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

}

}

for(byte i=0;i<10;i++)

{

System.out.println();

for(byte j=0;j<10;j++)

{

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

}

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

write a program of two matrices and show row and column wise

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program for Multiplication of two matrices in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you develop a JAVA program that computes matrices?

Matrices can't be "computed" as such; only operations like multiplication, transpose, addition, subtraction, etc., can be done. What can be computed are determinants. If you want to write a program that does operations such as these on matrices, I suggest using a two-dimensional array to store the values in the matrices, and use for-loops to iterate through the values.


Can we add website link when we write java program?

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


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

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


How do you write java program to times a number?

Java, like many other programming languages, uses the asterisk for the multiplication operator. Therefore, two numbers a and b are multiplied, and their product assigned to a variable r, with this construct: r = a * b;


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 a java program to find the ad joint of a matrix?

bgfygfrhjyuyhh


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.