{"id":38572,"date":"2024-11-26T09:43:44","date_gmt":"2024-11-26T01:43:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38572\/"},"modified":"2024-11-26T09:43:44","modified_gmt":"2024-11-26T01:43:44","slug":"java%e5%a4%9a%e7%bb%b4%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e7%ae%97%e5%b9%b3%e5%9d%87%e5%80%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38572\/","title":{"rendered":"java\u591a\u7ef4\u6570\u7ec4\u600e\u4e48\u7b97\u5e73\u5747\u503c"},"content":{"rendered":"<blockquote><p>\n  \u8ba1\u7b97\u591a\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\u9700\u8981\u5206\u6b65\u8ba1\u7b97\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u5e73\u5747\u503c\uff1a\u8ba1\u7b97\u6bcf\u4e2a\u4e00\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\uff1asum \/ count\u5bf9\u6240\u6709\u4e00\u7ef4\u6570\u7ec4\u5e73\u5747\u503c\u6c42\u5e73\u5747\uff0c\u5373\u6240\u6709\u4e00\u7ef4\u6570\u7ec4\u5e73\u5747\u503c\u4e4b\u548c \/ \u4e00\u7ef4\u6570\u7ec4\u6570\u91cf\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111503222543214.jpg\" class=\"aligncenter\" title=\"java\u591a\u7ef4\u6570\u7ec4\u600e\u4e48\u7b97\u5e73\u5747\u503c\u63d2\u56fe\" alt=\"java\u591a\u7ef4\u6570\u7ec4\u600e\u4e48\u7b97\u5e73\u5747\u503c\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u591a\u7ef4\u6570\u7ec4\u5e73\u5747\u503c\u8ba1\u7b97<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u591a\u7ef4\u6570\u7ec4\u662f\u6307\u5305\u542b\u591a\u4e2a\u7ef4\u5ea6\u5143\u7d20\u7684\u6570\u636e\u7ed3\u6784\u3002\u8ba1\u7b97\u591a\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\u9700\u8981\u5206\u522b\u8ba1\u7b97\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u5e73\u5747\u503c\u3002<\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li><strong>\u5b9a\u4e49\u591a\u7ef4\u6570\u7ec4\uff1a<\/strong><\/li>\n<\/ol>\n<pre>int[][] array = {\n    {1, 2, 3},\n    {4, 5, 6},\n    {7, 8, 9}\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li><strong>\u8ba1\u7b97\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u5e73\u5747\u503c\uff1a<\/strong><\/li>\n<\/ol>\n<ul>\n<li> <strong>\u4e00\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\uff1a<\/strong>average = sum \/ count\uff0c\u5176\u4e2d sum \u4e3a\u5143\u7d20\u4e4b\u548c\uff0ccount \u4e3a\u5143\u7d20\u6570\u91cf\u3002<\/li>\n<li> <strong>\u591a\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\uff1a<\/strong>\u5148\u8ba1\u7b97\u6bcf\u4e2a\u4e00\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\uff0c\u7136\u540e\u5bf9\u6240\u6709\u4e00\u7ef4\u6570\u7ec4\u5e73\u5747\u503c\u6c42\u5e73\u5747\u3002<\/li>\n<\/ul>\n<ol>\n<li><strong>\u5177\u4f53\u8ba1\u7b97\uff1a<\/strong><\/li>\n<\/ol>\n<pre>\/\/ \u8ba1\u7b97\u6bcf\u4e2a\u4e00\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\ndouble[] oneDArrayAverages = new double[array.length];\nfor (int i = 0; i &lt; array.length; i++) {\n    int sum = 0;\n    for (int j = 0; j &lt; array[i].length; j++) {\n        sum += array[i][j];\n    }\n    oneDArrayAverages[i] = (double) sum \/ array[i].length;\n}\n\n\/\/ \u8ba1\u7b97\u591a\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\ndouble average = 0;\nfor (double oneDArrayAverage : oneDArrayAverages) {\n    average += oneDArrayAverage;\n}\naverage \/= oneDArrayAverages.length;\n\nSystem.out.println(\"\u591a\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\uff1a\" + average);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>\u591a\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\uff1a5.0<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u591a\u7ef4\u6570\u7ec4\u600e\u4e48\u7b97\u5e73\u5747\u503c\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>\u8ba1\u7b97\u591a\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\u9700\u8981\u5206\u6b65\u8ba1\u7b97\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u5e73\u5747\u503c\uff1a\u8ba1\u7b97\u6bcf\u4e2a\u4e00\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\uff1asum \/ count\u5bf9\u6240\u6709\u4e00\u7ef4\u6570\u7ec4\u5e73\u5747\u503c\u6c42\u5e73\u5747\uff0c\u5373\u6240\u6709\u4e00\u7ef4\u6570\u7ec4\u5e73\u5747\u503c\u4e4b\u548c \/ \u4e00\u7ef4\u6570\u7ec4\u6570\u91cf Java \u591a\u7ef4\u6570\u7ec4\u5e73\u5747\u503c\u8ba1\u7b97 \u5728 Java \u4e2d\uff0c\u591a\u7ef4\u6570\u7ec4\u662f\u6307\u5305\u542b\u591a\u4e2a\u7ef4\u5ea6\u5143\u7d20\u7684\u6570\u636e\u7ed3\u6784\u3002\u8ba1\u7b97\u591a\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\u9700\u8981\u5206\u522b\u8ba1\u7b97\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u5e73\u5747\u503c\u3002 \u6b65\u9aa4\uff1a \u5b9a\u4e49\u591a\u7ef4\u6570\u7ec4\uff1a int[][] array = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; \u767b\u5f55\u540e\u590d\u5236 \u8ba1\u7b97\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u5e73\u5747\u503c\uff1a \u4e00\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\uff1aaverage = sum \/ count\uff0c\u5176\u4e2d sum \u4e3a\u5143\u7d20\u4e4b\u548c\uff0ccount \u4e3a\u5143\u7d20\u6570\u91cf\u3002 \u591a\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\uff1a\u5148\u8ba1\u7b97\u6bcf\u4e2a\u4e00\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c\uff0c\u7136\u540e\u5bf9\u6240\u6709\u4e00\u7ef4\u6570\u7ec4\u5e73\u5747\u503c\u6c42\u5e73\u5747\u3002 \u5177\u4f53\u8ba1\u7b97\uff1a \/\/ \u8ba1\u7b97\u6bcf\u4e2a\u4e00\u7ef4\u6570\u7ec4\u7684\u5e73\u5747\u503c double[] oneDArrayAverages = new double[array.length]; for (int i = 0; i &lt; array.length; i++) { [&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-38572","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38572","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=38572"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38572\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}