Matrix Operation In Java

18 comments - Post a comment

/******* Java Implementation of Matrix Operation Using Arrays *******/

class Matrix
{
public static void main(String args[])
{
int i,j,k;
int mat1 [][]={ {10,11,12}, {13,14,15}, {16,17,18} };
int mat2 [][]={ {1,2,3}, {4,5,6}, {7,8,9} };
System.out.println("Operation ON Matrices \n1.Addition \n");
int sum [][] = new int [3][3];
for(i=0;i <3;i++)
{
for(j=0;j< 3;j++)
{
sum[i][j] = mat1[i][j] + mat2[i][j];
System.out.print("\t" + sum[i][j]);
}
System.out.println("\t");
}

System.out.println("2.Subtraction\n");
int diff[][] = new int[3][3];
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
diff [i][j] = mat1[i][j] - mat2[i][j];
System.out.print("\t"+ diff[i][j]);
}
System.out.println("\t");
}

System.out.println("3.Multiplication\n");
int prod[][] = new int[3][3];
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
prod[i][j] = 0;
{
for(k=0;k< 3;k++)
prod[i][j] = prod[i][j]+mat1[i][k]*mat2[k][j];
}
System.out.print("\t"+ prod[i][j]);
}
System.out.println("\t");

}
}
}

/************* OUTPUT ***************

Operation ON Matrices
1.Addition

11 13 15
17 19 21
23 25 27
2.Subtraction

9 9 9
9 9 9
9 9 9
3.Multiplication

138 171 204
174 216 258
210 261 312 */

 
This Post has 18 Comments Add your own!
john michael - September 5, 2009 at 8:18 AM

hello..it really helps us a lot...

john michael - September 5, 2009 at 8:19 AM

hello...it really helps us a lot!!!!!...

faye - May 12, 2010 at 2:00 PM

THANK YOU VERY MUCH!
MORE POWER AND GOD BLESS!

anuja - June 3, 2010 at 10:31 PM

thanks a lot.........

iron girl - July 19, 2010 at 2:41 PM

thank ye!!it helped me

iron girl - July 19, 2010 at 2:42 PM

thank ye!!it helped me

Chakri - January 5, 2011 at 2:21 PM

thnks u

Chakri - January 5, 2011 at 2:21 PM

thnks u

Chakri - January 5, 2011 at 2:22 PM

thnk u

noor - March 1, 2011 at 8:49 PM

thank u so much
need a program in which decimal number change into roman numbers

Anonymous - March 13, 2011 at 11:57 AM

what abt division"?

Anonymous - July 19, 2011 at 6:04 PM

really a helpful thanks a lot

Anonymous - November 22, 2011 at 8:57 AM

Thanks a lot. It's very easy to understand.

Anonymous - February 16, 2012 at 10:40 PM

its helps me a lot...
its very easy...
want div code,just like it..........easy.....................................................................





THANKS................................

swamivivekanandahometutions - April 10, 2012 at 5:30 AM

prod[i][j] = 0;
{
for(k=0;k< 3;k++)
prod[i][j] = prod[i][j]+mat1[i][k]*mat2[k][j];

Explain the above logic

swamivivekanandahometutions - April 10, 2012 at 5:31 AM

prod[i][j] = 0;
{
for(k=0;k< 3;k++)
prod[i][j] = prod[i][j]+mat1[i][k]*mat2[k][j];

Explain the above logic

mauran panchalingam - August 22, 2012 at 8:14 PM

this is very use full sight for java users

mauran panchalingam - August 22, 2012 at 8:15 PM

it is a good blog
all java users

Post a Comment