题解 | #矩阵乘法#

矩阵乘法

https://www.nowcoder.com/practice/ebe941260f8c4210aa8c17e99cbc663b

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner fzhinput = new Scanner(System.in);
        int h1 = fzhinput.nextInt();
        int l1 = fzhinput.nextInt();
        int h2 = l1;
        int l2 = fzhinput.nextInt();
        int jz1[][] = new int[h1][l1];
        int jz2[][] = new int[h2][l2];
        int jz3[][] = new int[h1][l2];
        for (int i = 0; i < h1; i++) {
            for (int j = 0; j < l1; j++) {
                jz1[i][j] = fzhinput.nextInt();
            }
        }

        for (int i = 0; i < h2; i++) {
            for (int j = 0; j < l2; j++) {
                jz2[i][j] = fzhinput.nextInt();
            }
        }

        for (int i = 0; i < h1; i++) {
            for (int j = 0; j < l2; j++) {
                for (int z = 0; z < l1; z++) {
                    jz3[i][j] += jz1[i][z] * jz2[z][j];
                }
            }
        }

        for (int i = 0; i < h1; i++) {
            for (int j = 0; j < l2; j++) {  
                System.out.print(jz3[i][j]+" ");    
            }
            System.out.println();
        }
    }
}

全部评论

相关推荐

海康威视 软开岗 15k15
点赞 评论 收藏
分享
11-18 15:57
门头沟学院 Java
最终归宿是测开:这个重邮的大佬在重邮很有名的,他就喜欢打92的脸,越有人质疑他,他越觉得爽😂
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务