{"id":35006,"date":"2024-11-26T13:10:12","date_gmt":"2024-11-26T05:10:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35006\/"},"modified":"2024-11-26T13:10:12","modified_gmt":"2024-11-26T05:10:12","slug":"java%e4%b8%a4%e4%b8%aa%e6%95%b0%e7%bb%84%e7%9b%b8%e4%b9%98%e6%80%8e%e4%b9%88%e8%bf%90%e7%ae%97%e7%9a%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/35006\/","title":{"rendered":"java\u4e24\u4e2a\u6570\u7ec4\u76f8\u4e58\u600e\u4e48\u8fd0\u7b97\u7684"},"content":{"rendered":"<blockquote><p>\n  java\u4e2d\u4e24\u4e2a\u6570\u7ec4\u76f8\u4e58\u7684\u8fd0\u7b97\u985e\u4f3c\u65bc\u77e9\u9663\u4e58\u6cd5\uff1a\u7d50\u679c\u9663\u5217c\u7684\u884c\u6578\u70baa\u7684\u884c\u6578\uff0c\u5217\u6578\u70bab\u7684\u5217\u6578\u3002c\u4e2d\u6bcf\u500b\u5143\u7d20\u7531a\u5c0d\u61c9\u884c\u6240\u6709\u5143\u7d20\u8207b\u5c0d\u61c9\u5217\u6240\u6709\u5143\u7d20\u76f8\u4e58\u5f8c\u6c42\u548c\u5f97\u5230\u3002\u5982\u4e0bjava\u7a0b\u5f0f\u78bc\u6240\u793a\uff0cmultiply\u51fd\u6578\u5be6\u73fe\u4e86\u4e0a\u8ff0\u904b\u7b97\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/03\/2024110308161423703.jpg\" class=\"aligncenter\" title=\"java\u4e24\u4e2a\u6570\u7ec4\u76f8\u4e58\u600e\u4e48\u8fd0\u7b97\u7684\u63d2\u56fe\" alt=\"java\u4e24\u4e2a\u6570\u7ec4\u76f8\u4e58\u600e\u4e48\u8fd0\u7b97\u7684\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u4e24\u4e2a\u6570\u7ec4\u76f8\u4e58\u7684\u8fd0\u7b97<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684\u4e58\u6cd5\u4e0e\u77e9\u9635\u4e58\u6cd5\u7c7b\u4f3c\u3002\u5bf9\u4e8e\u5177\u6709 m \u884c n \u5217\u7684\u6570\u7ec4 A \u548c\u5177\u6709 p \u884c q \u5217\u7684\u6570\u7ec4 B\uff0c\u5b83\u4eec\u7684\u4e58\u79ef C \u5c06\u662f\u4e00\u4e2a\u5177\u6709 m \u884c q \u5217\u7684\u6570\u7ec4\uff0c\u5176\u5143\u7d20\u8ba1\u7b97\u5982\u4e0b\uff1a<\/p>\n<p><strong>Ci = \u03a3(Ai * Bk), k = 0 to min(n, p)<\/strong><\/p>\n<p>\u6362\u53e5\u8bdd\u8bf4\uff0cC \u7684\u7b2c i \u884c\u548c\u7b2c j \u5217\u7684\u5143\u7d20\u662f A \u7684\u7b2c i \u884c\u7684\u6240\u6709\u5143\u7d20\u4e0e B \u7684\u7b2c j \u5217\u7684\u6240\u6709\u5143\u7d20\u76f8\u4e58\u540e\u518d\u6c42\u548c\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u8003\u8651\u4ee5\u4e0b\u4e24\u4e2a\u6570\u7ec4\uff1a<\/p>\n<pre>int[][] A = {\n    {1, 2},\n    {3, 4}\n};\n\nint[][] B = {\n    {5, 6},\n    {7, 8}\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5b83\u4eec\u7684\u4e58\u79ef C \u5c06\u4e3a\uff1a<\/p>\n<pre>int[][] C = {\n    {19, 22},\n    {43, 50}\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5b9e\u73b0<\/strong><\/p>\n<p>\u4ee5\u4e0b Java \u4ee3\u7801\u5b9e\u73b0\u4e86\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684\u4e58\u6cd5\uff1a<\/p>\n<pre>public class ArrayMultiplication {\n\n    public static void main(String[] args) {\n        int[][] A = {\n            {1, 2},\n            {3, 4}\n        };\n\n        int[][] B = {\n            {5, 6},\n            {7, 8}\n        };\n\n        int[][] C = multiply(A, B);\n\n        for (int i = 0; i &lt; C.length; i++) {\n            for (int j = 0; j &lt; C[0].length; j++) {\n                System.out.print(C[i][j] + \" \");\n            }\n            System.out.println();\n        }\n    }\n\n    public static int[][] multiply(int[][] A, int[][] B) {\n        int m = A.length; \/\/ A \u7684\u884c\u6570\n        int n = B.length; \/\/ B \u7684\u5217\u6570\n        int q = B[0].length; \/\/ B \u7684\u884c\u6570\uff08\u4e5f\u7b49\u4e8e C \u7684\u5217\u6570\uff09\n\n        int[][] C = new int[m][q];\n\n        for (int i = 0; i &lt; m; i++) {\n            for (int j = 0; j &lt; q; j++) {\n                for (int k = 0; k &lt; n; k++) {\n                    C[i][j] += A[i][k] * B[k][j];\n                }\n            }\n        }\n\n        return C;\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>19 22\n43 50<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u4e24\u4e2a\u6570\u7ec4\u76f8\u4e58\u600e\u4e48\u8fd0\u7b97\u7684\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>java\u4e2d\u4e24\u4e2a\u6570\u7ec4\u76f8\u4e58\u7684\u8fd0\u7b97\u985e\u4f3c\u65bc\u77e9\u9663\u4e58\u6cd5\uff1a\u7d50\u679c\u9663\u5217c\u7684\u884c\u6578\u70baa\u7684\u884c\u6578\uff0c\u5217\u6578\u70bab\u7684\u5217\u6578\u3002c\u4e2d\u6bcf\u500b\u5143\u7d20\u7531a\u5c0d\u61c9\u884c\u6240\u6709\u5143\u7d20\u8207b\u5c0d\u61c9\u5217\u6240\u6709\u5143\u7d20\u76f8\u4e58\u5f8c\u6c42\u548c\u5f97\u5230\u3002\u5982\u4e0bjava\u7a0b\u5f0f\u78bc\u6240\u793a\uff0cmultiply\u51fd\u6578\u5be6\u73fe\u4e86\u4e0a\u8ff0\u904b\u7b97\u3002 Java \u4e2d\u4e24\u4e2a\u6570\u7ec4\u76f8\u4e58\u7684\u8fd0\u7b97 \u5728 Java \u4e2d\uff0c\u4e24\u4e2a\u6570\u7ec4\u4e4b\u95f4\u7684\u4e58\u6cd5\u4e0e\u77e9\u9635\u4e58\u6cd5\u7c7b\u4f3c\u3002\u5bf9\u4e8e\u5177\u6709 m \u884c n \u5217\u7684\u6570\u7ec4 A \u548c\u5177\u6709 p \u884c q \u5217\u7684\u6570\u7ec4 B\uff0c\u5b83\u4eec\u7684\u4e58\u79ef C \u5c06\u662f\u4e00\u4e2a\u5177\u6709 m \u884c q \u5217\u7684\u6570\u7ec4\uff0c\u5176\u5143\u7d20\u8ba1\u7b97\u5982\u4e0b\uff1a Ci = \u03a3(Ai * Bk), k = 0 to min(n, p) \u6362\u53e5\u8bdd\u8bf4\uff0cC \u7684\u7b2c i \u884c\u548c\u7b2c j \u5217\u7684\u5143\u7d20\u662f A \u7684\u7b2c i \u884c\u7684\u6240\u6709\u5143\u7d20\u4e0e B \u7684\u7b2c j \u5217\u7684\u6240\u6709\u5143\u7d20\u76f8\u4e58\u540e\u518d\u6c42\u548c\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u793a\u4f8b \u8003\u8651\u4ee5\u4e0b\u4e24\u4e2a\u6570\u7ec4\uff1a int[][] A = { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-35006","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35006","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=35006"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35006\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35006"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35006"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}