编程语言
首页 > 编程语言> > 5.15 题目要求 有下面两个矩阵 求a和b的合 编写程序,计算A+B A-B 矩阵A的转置

5.15 题目要求 有下面两个矩阵 求a和b的合 编写程序,计算A+B A-B 矩阵A的转置

作者:互联网

package bookTest3;

public class test5_15 {
    public static void main(String[] args) {
        /*
        题目要求
          有下面两个矩阵 求a和b的合
          编写程序,计算A+B A-B 矩阵A的转置
         */
        int [][] A={{1,3,5},{-3,6,0},{13,-5,7},{-2,19,25}};
        int [][] B={{0,-1,-2},{7,-1,6},{-6,13,2},{12,-8,-13}};
        int [][] c=new int[4][3];
        //计算矩阵加法
        for (int i = 0; i < 4 ; i++) {
            for (int j = 0; j < 3; j++) {
               // System.out.println(A[i][j]);都可以获取的到
               // System.out.println(B[i][j]);
               c[i][j] = A[i][j] +B[i][j];
            }
        }
        for (int i = 0; i <4 ; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.print(c[i][j]+" ");
            }
            System.out.println();
        }
        //计算A-B
        System.out.println("      ");
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 3; j++) {
                c[i][j] = A[i][j] - B[i][j];
            }
        }
        for (int i = 0; i <4 ; i++) {
            for (int j = 0; j <3 ; j++) {
                System.out.print(c[i][j]+" "+" ");
            }
            System.out.println();

        }
        System.out.println("   ");
        //计算A的转置 意思就是行变成列 列变成行 建立一个数组保存它 d
        int [][] D = new int[3][4];
        for (int i = 0; i <3; i++) {
            for (int j = 0; j <4 ; j++) {
               //行这输出A
               // System.out.print(A[j][i]+" ");
                D[i][j] = A[j][i];
            }
        }
        for (int i = 0; i <3 ; i++) {
            for (int j = 0; j <4 ; j++) {
                System.out.print(D[i][j]+"  ");
            }
            System.out.println();

        }



    }
}

结果图

标签:13,转置,矩阵,System,int,5.15,out
来源: https://blog.csdn.net/liuwenqing11/article/details/111088668