LIL_HOOK
LIL_HOOK
采纳率0%
2021-03-02 17:49

Java 两个矩阵相加赋值

要在赋值矩阵C 计算 计算矩阵每一行的最小元素之和

最后计算过程中 无法赋值C 求助

public class MAIN1 { public static void main(String[] args) {
    final double[][] A =
            {
                    {1, 2, 3},
                    {4, 5, 6},
                    {7, 8, 9}
            };
    for (int i = 0; i < A.length; i++) {
        for (int j = 0; j < A[i].length; j++) {
            System.out.print(A[i][j] + " ");
        }
        System.out.println();
    }


    System.out.println("++++++++++++++");

    final double[][] B =
            {
                    {1, 2, 3},
                    {4, 5, 6},
                    {7, 8, 9}
            };
    for (int i = 0; i < B.length; i++) {
        for (int j = 0; j < B[i].length; j++) {
            System.out.print(B[i][j] + " ");
        }
        System.out.println();
    }

    System.out.println("==============");



    for (int i = 0; i < B.length; i++) {
        for (int j = 0; j < B[i].length; j++) {
            final double C = A[i][j] + B[i][j];
            System.out.print(C);

        };
        System.out.println();}



    double min;
    double S = 0;
    for (int i = 0; i < B[0].length; i++) {
        min = B[i][0];
        for (int j = 0; j < B.length; j++) {
            if (min > B[i][j])
            {
                min = B[i][j];
            }
        }
        S += min;
    }

    System.out.println(S);}
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • qq_25376897 qq_25376897 1月前

    可以赋值C呀

    点赞 评论 复制链接分享

为你推荐