public class arraydemomatrixadd {
static void matrixadd(int x[][],int y[][])
{
int i,j,k;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print(x[i][j]+" ");
}
System.out.print(" ");
for(k=0;k<3;k++)
{
System.out.print(y[i][k]+" ");
}
System.out.println("");
}
int z[][];
z=new int[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
z[i][j]= x[i][j]+y[i][j];
System.out.print(z[i][j]+" ");
}
System.out.println("");
}
}
public static void main(String[] args)
{
matrixadd(new int[][]{{1,2,3},{4,5,6},{7,8,9}},new int[][]{{1,2,3},{4,5,6},{7,8,9}});
}
}
No comments:
Post a Comment