{"id":39465,"date":"2024-11-26T08:24:21","date_gmt":"2024-11-26T00:24:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/39465\/"},"modified":"2024-11-26T08:24:21","modified_gmt":"2024-11-26T00:24:21","slug":"java%e6%80%8e%e4%b9%88%e7%94%b3%e8%af%b7n%e4%b8%aa%e5%85%83%e7%b4%a0%e7%9a%84%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/39465\/","title":{"rendered":"java\u600e\u4e48\u7533\u8bf7n\u4e2a\u5143\u7d20\u7684\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\u7533\u8bf7 n \u4e2a\u5143\u7d20\u7684\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528 new \u5173\u952e\u5b57\uff1aint[] myarray = new int[n];\u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668\uff1aint[] myarray = {1, 2, 3, 4, 5};\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111611182596043.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u7533\u8bf7n\u4e2a\u5143\u7d20\u7684\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u7533\u8bf7n\u4e2a\u5143\u7d20\u7684\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Java \u4e2d\u7533\u8bf7 n \u4e2a\u5143\u7d20\u7684\u6570\u7ec4<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4e24\u79cd\u65b9\u6cd5\u6765\u7533\u8bf7 n \u4e2a\u5143\u7d20\u7684\u6570\u7ec4\uff1a<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528 new \u5173\u952e\u5b57<\/strong><\/p>\n<p>\u8fd9\u662f\u521b\u5efa\u6570\u7ec4\u7684\u6700\u5e38\u7528\u65b9\u6cd5\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[] myArray = new int[n];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u8bed\u53e5\u521b\u5efa\u4e00\u4e2a\u5927\u5c0f\u4e3a n \u7684 int \u578b\u6570\u7ec4\uff0c\u5176\u4e2d n \u662f\u60a8\u8981\u7533\u8bf7\u7684\u5143\u7d20\u6570\u91cf\u3002<\/p>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u77e5\u9053\u6570\u7ec4\u4e2d\u7684\u521d\u59cb\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668\uff1a<\/p>\n<pre>int[] myArray = {1, 2, 3, 4, 5};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u8bed\u53e5\u521b\u5efa\u4e00\u4e2a\u5927\u5c0f\u4e3a 5 \u7684 int \u578b\u6570\u7ec4\uff0c\u5176\u4e2d\u5143\u7d20\u521d\u59cb\u5316\u4e3a 1 \u5230 5\u3002<\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u60a8\u8981\u521b\u5efa\u5927\u5c0f\u4e3a 10 \u7684\u53cc\u7cbe\u5ea6\u6570\u7ec4\uff0c\u53ef\u4ee5\u6309\u5982\u4e0b\u65b9\u5f0f\u8fdb\u884c\uff1a<\/p>\n<p><strong>\u4f7f\u7528 new \u5173\u952e\u5b57<\/strong><\/p>\n<pre>double[] myArray = new double[10];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668<\/strong><\/p>\n<pre>double[] myArray = {1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u7533\u8bf7n\u4e2a\u5143\u7d20\u7684\u6570\u7ec4\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>\u5728 java \u4e2d\u7533\u8bf7 n \u4e2a\u5143\u7d20\u7684\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528 new \u5173\u952e\u5b57\uff1aint[] myarray = new int[n];\u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668\uff1aint[] myarray = {1, 2, 3, 4, 5}; \u5982\u4f55\u5728 Java \u4e2d\u7533\u8bf7 n \u4e2a\u5143\u7d20\u7684\u6570\u7ec4 \u5728 Java \u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4e24\u79cd\u65b9\u6cd5\u6765\u7533\u8bf7 n \u4e2a\u5143\u7d20\u7684\u6570\u7ec4\uff1a \u65b9\u6cd5 1\uff1a\u4f7f\u7528 new \u5173\u952e\u5b57 \u8fd9\u662f\u521b\u5efa\u6570\u7ec4\u7684\u6700\u5e38\u7528\u65b9\u6cd5\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b int[] myArray = new int[n]; \u767b\u5f55\u540e\u590d\u5236 \u8be5\u8bed\u53e5\u521b\u5efa\u4e00\u4e2a\u5927\u5c0f\u4e3a n \u7684 int \u578b\u6570\u7ec4\uff0c\u5176\u4e2d n \u662f\u60a8\u8981\u7533\u8bf7\u7684\u5143\u7d20\u6570\u91cf\u3002 \u65b9\u6cd5 2\uff1a\u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668 \u5982\u679c\u60a8\u77e5\u9053\u6570\u7ec4\u4e2d\u7684\u521d\u59cb\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668\uff1a int[] myArray = {1, 2, [&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-39465","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39465","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=39465"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39465\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=39465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=39465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=39465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}