{"id":38867,"date":"2024-11-26T09:36:47","date_gmt":"2024-11-26T01:36:47","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38867\/"},"modified":"2024-11-26T09:36:47","modified_gmt":"2024-11-26T01:36:47","slug":"java%e6%95%b0%e7%bb%84%e8%be%93%e5%85%a5%e6%b5%ae%e7%82%b9%e6%95%b0%e6%80%8e%e4%b9%88%e8%ae%a1%e7%ae%97","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38867\/","title":{"rendered":"java\u6570\u7ec4\u8f93\u5165\u6d6e\u70b9\u6570\u600e\u4e48\u8ba1\u7b97"},"content":{"rendered":"<blockquote><p>\n  \u8ba1\u7b97 java \u6570\u7ec4\u4e2d\u6d6e\u70b9\u6570\u7684\u603b\u548c\u6b65\u9aa4\uff1a1. \u521d\u59cb\u5316\u6570\u7ec4\u548c\u53d8\u91cf\uff1b2. \u904d\u5386\u6570\u7ec4\uff0c\u5c06\u5143\u7d20\u6dfb\u52a0\u5230\u603b\u548c\u4e2d\uff1b3. \u6253\u5370\u603b\u548c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111507332468088.jpg\" class=\"aligncenter\" title=\"java\u6570\u7ec4\u8f93\u5165\u6d6e\u70b9\u6570\u600e\u4e48\u8ba1\u7b97\u63d2\u56fe\" alt=\"java\u6570\u7ec4\u8f93\u5165\u6d6e\u70b9\u6570\u600e\u4e48\u8ba1\u7b97\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u8ba1\u7b97 Java \u6570\u7ec4\u4e2d\u7684\u6d6e\u70b9\u6570<\/strong><\/p>\n<p><strong>\u5f00\u95e8\u89c1\u5c71\u56de\u7b54\uff1a<\/strong><\/p>\n<p>\u8ba1\u7b97 Java \u6570\u7ec4\u4e2d\u6d6e\u70b9\u6570\u7684\u603b\u548c\u53ef\u4ee5\u6309\u5982\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a<\/p>\n<p><strong>\u8be6\u7ec6\u5c55\u5f00\u56de\u7b54\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>1. \u5b9a\u4e49\u548c\u521d\u59cb\u5316\u6570\u7ec4<\/strong><\/p>\n<pre>float[] numbers = {1.5f, 2.3f, 4.5f, 6.7f};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u58f0\u660e\u53d8\u91cf\u4ee5\u5b58\u50a8\u603b\u548c<\/strong><\/p>\n<pre>float sum = 0f;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u904d\u5386\u6570\u7ec4<\/strong><\/p>\n<pre>for (float number : numbers) {\n    sum += number;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u6253\u5370\u603b\u548c<\/strong><\/p>\n<pre>System.out.println(\"\u603b\u548c\uff1a\" + sum);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre>\u603b\u548c\uff1a14.5<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u6570\u7ec4\u4e2d\u6240\u6709\u5143\u7d20\u90fd\u662f\u6d6e\u70b9\u6570\uff0c\u5426\u5219\u5c06\u51fa\u73b0\u6216\u8fd0\u884c\u65f6\u5f02\u5e38\u3002<\/li>\n<li>\u58f0\u660e\u603b\u548c\u53d8\u91cf\u65f6\uff0c\u4f7f\u7528\u6d6e\u70b9\u6570\uff0c\u56e0\u4e3a\u6570\u7ec4\u5143\u7d20\u662f\u6d6e\u70b9\u6570\u3002<\/li>\n<li>\u5728\u5faa\u73af\u4e2d\uff0c\u4f7f\u7528 += \u8fd0\u7b97\u7b26\u5c06\u5f53\u524d\u5143\u7d20\u6dfb\u52a0\u5230\u603b\u548c\u4e2d\u3002<\/li>\n<li>\u4f7f\u7528 System.out.println() \u65b9\u6cd5\u6253\u5370\u7ed3\u679c\uff0c\u5176\u4e2d sum \u662f\u8981\u6253\u5370\u7684\u6d6e\u70b9\u6570\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u6570\u7ec4\u8f93\u5165\u6d6e\u70b9\u6570\u600e\u4e48\u8ba1\u7b97\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 java \u6570\u7ec4\u4e2d\u6d6e\u70b9\u6570\u7684\u603b\u548c\u6b65\u9aa4\uff1a1. \u521d\u59cb\u5316\u6570\u7ec4\u548c\u53d8\u91cf\uff1b2. \u904d\u5386\u6570\u7ec4\uff0c\u5c06\u5143\u7d20\u6dfb\u52a0\u5230\u603b\u548c\u4e2d\uff1b3. \u6253\u5370\u603b\u548c\u3002 \u5982\u4f55\u8ba1\u7b97 Java \u6570\u7ec4\u4e2d\u7684\u6d6e\u70b9\u6570 \u5f00\u95e8\u89c1\u5c71\u56de\u7b54\uff1a \u8ba1\u7b97 Java \u6570\u7ec4\u4e2d\u6d6e\u70b9\u6570\u7684\u603b\u548c\u53ef\u4ee5\u6309\u5982\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a \u8be6\u7ec6\u5c55\u5f00\u56de\u7b54\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b 1. \u5b9a\u4e49\u548c\u521d\u59cb\u5316\u6570\u7ec4 float[] numbers = {1.5f, 2.3f, 4.5f, 6.7f}; \u767b\u5f55\u540e\u590d\u5236 2. \u58f0\u660e\u53d8\u91cf\u4ee5\u5b58\u50a8\u603b\u548c float sum = 0f; \u767b\u5f55\u540e\u590d\u5236 3. \u904d\u5386\u6570\u7ec4 for (float number : numbers) { sum += number; } \u767b\u5f55\u540e\u590d\u5236 4. \u6253\u5370\u603b\u548c System.out.println(&#8220;\u603b\u548c\uff1a&#8221; + sum); \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\u8f93\u51fa\uff1a \u603b\u548c\uff1a14.5 \u767b\u5f55\u540e\u590d\u5236 \u6ce8\u610f\u4e8b\u9879\uff1a [&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-38867","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38867","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=38867"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38867\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38867"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}