public class Matrix {
/**
* 打印指定的矩阵
* @param c
*/
public static void printMatrix(int[][] c){
//打印矩阵
for(int i=0;i<c.length;i++){
for(int j=0;j<c.length;j++){
System.out.print(c[i][j]+" ");
}
System.out.println();
}
}
/**
* 矩阵加法
* @param a
* @param b
* @return
*/
public static int[][]
addMatrix(int [][]a,int [][]b){
int [][]c=new int[a.length][b.length];
for(int i=0;i<c.length;i++){
for(int j=0;j<c.length;j++){
c[i][j]=a[i][j]+b[i][j];
}
}
return c;
}
public static void main(String[] args){
int [][]a={
{1,3},
{2,4}
};
int [][]b={
{3,4},
{5,6}
};
int[][] c=addMatrix(a,b);
printMatrix(c);
}
}