{"id":66277,"date":"2025-05-03T16:54:29","date_gmt":"2025-05-03T08:54:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66277\/"},"modified":"2025-05-03T16:54:29","modified_gmt":"2025-05-03T08:54:29","slug":"java%e6%80%8e%e4%b9%88%e6%8a%8a%e6%95%b0%e7%bb%84%e4%b8%ad%e9%97%b4%e7%9a%84%e5%85%83%e7%b4%a0%e5%88%a0%e9%99%a4-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66277\/","title":{"rendered":"java\u600e\u4e48\u628a\u6570\u7ec4\u4e2d\u95f4\u7684\u5143\u7d20\u5220\u9664"},"content":{"rendered":"<blockquote><p>\n  \u8981\u4ece java \u6570\u7ec4\u4e2d\u5220\u9664\u4e2d\u95f4\u5143\u7d20\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a\u521b\u5efa\u65b0\u6570\u7ec4\uff0c\u5927\u5c0f\u6bd4\u539f\u59cb\u6570\u7ec4\u5c0f 1\u3002\u5c06\u4e2d\u95f4\u5143\u7d20\u4e4b\u524d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\u3002\u5c06\u4e2d\u95f4\u5143\u7d20\u4e4b\u540e\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\uff0c\u5c06\u5176\u7d22\u5f15\u51cf\u5c11 1\u3002\u5c06\u65b0\u6570\u7ec4\u8d4b\u503c\u7ed9\u539f\u59cb\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111505551725364.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u628a\u6570\u7ec4\u4e2d\u95f4\u7684\u5143\u7d20\u5220\u9664\u63d2\u56fe\" alt=\"java\u600e\u4e48\u628a\u6570\u7ec4\u4e2d\u95f4\u7684\u5143\u7d20\u5220\u9664\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5220\u9664 Java \u6570\u7ec4\u4e2d\u7684\u4e2d\u95f4\u5143\u7d20<\/strong><\/p>\n<p>\u8981\u4ece Java \u6570\u7ec4\u4e2d\u5220\u9664\u4e2d\u95f4\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u4e00\u4e2a\u6570\u7ec4<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a Java \u6570\u7ec4\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[] arr = {1, 2, 3, 4, 5, 6, 7};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u8ba1\u7b97\u4e2d\u95f4\u7d22\u5f15<\/strong><\/p>\n<p>\u8981\u5220\u9664\u4e2d\u95f4\u5143\u7d20\uff0c\u9700\u8981\u8ba1\u7b97\u6570\u7ec4\u7684\u4e2d\u95f4\u7d22\u5f15\uff1a<\/p>\n<pre>int middleIdx = arr.length \/ 2;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5bf9\u4e8e\u5076\u6570\u957f\u5ea6\u7684\u6570\u7ec4\uff0c\u4e2d\u95f4\u7d22\u5f15\u5c06\u5728\u4e24\u4e2a\u4e2d\u95f4\u5143\u7d20\u4e4b\u95f4\u3002<\/p>\n<p><strong>3. \u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\u6765\u5b58\u50a8\u5220\u53bb\u4e2d\u95f4\u5143\u7d20\u540e\u7684\u6570\u7ec4\uff1a<\/p>\n<pre>int[] newArr = new int[arr.length - 1];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u590d\u5236\u5143\u7d20<\/strong><\/p>\n<p>\u5c06\u4e2d\u95f4\u5143\u7d20\u4e4b\u524d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\uff1a<\/p>\n<pre>for (int i = 0; i &lt; middleIdx; i++) {\n    newArr[i] = arr[i];\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5c06\u4e2d\u95f4\u5143\u7d20\u4e4b\u540e\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\uff1a<\/p>\n<pre>for (int i = middleIdx + 1; i &lt; arr.length; i++) {\n    newArr[i - 1] = arr[i];\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u5c06\u65b0\u6570\u7ec4\u8d4b\u503c\u7ed9\u539f\u59cb\u6570\u7ec4<\/strong><\/p>\n<p>\u6700\u540e\uff0c\u5c06\u65b0\u6570\u7ec4\u8d4b\u503c\u7ed9\u539f\u59cb\u6570\u7ec4\uff1a<\/p>\n<pre>arr = newArr;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>public static void main(String[] args) {\n    int[] arr = {1, 2, 3, 4, 5, 6, 7};\n    int middleIdx = arr.length \/ 2;\n    int[] newArr = new int[arr.length - 1];\n    for (int i = 0; i &lt; middleIdx; i++) {\n        newArr[i] = arr[i];\n    }\n    for (int i = middleIdx + 1; i &lt; arr.length; i++) {\n        newArr[i - 1] = arr[i];\n    }\n    System.out.println(Arrays.toString(newArr));\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>[1, 2, 3, 5, 6, 7]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u628a\u6570\u7ec4\u4e2d\u95f4\u7684\u5143\u7d20\u5220\u9664\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u4ece java \u6570\u7ec4\u4e2d\u5220\u9664\u4e2d\u95f4\u5143\u7d20\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a\u521b\u5efa\u65b0\u6570\u7ec4\uff0c\u5927\u5c0f\u6bd4\u539f\u59cb\u6570\u7ec4\u5c0f 1\u3002\u5c06\u4e2d\u95f4\u5143\u7d20\u4e4b\u524d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\u3002\u5c06\u4e2d\u95f4\u5143\u7d20\u4e4b\u540e\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\uff0c\u5c06\u5176\u7d22\u5f15\u51cf\u5c11 1\u3002\u5c06\u65b0\u6570\u7ec4\u8d4b\u503c\u7ed9\u539f\u59cb\u6570\u7ec4\u3002 \u5982\u4f55\u5220\u9664 Java \u6570\u7ec4\u4e2d\u7684\u4e2d\u95f4\u5143\u7d20 \u8981\u4ece Java \u6570\u7ec4\u4e2d\u5220\u9664\u4e2d\u95f4\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u521b\u5efa\u4e00\u4e2a\u6570\u7ec4 \u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a Java \u6570\u7ec4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b int[] arr = {1, 2, 3, 4, 5, 6, 7}; \u767b\u5f55\u540e\u590d\u5236 2. \u8ba1\u7b97\u4e2d\u95f4\u7d22\u5f15 \u8981\u5220\u9664\u4e2d\u95f4\u5143\u7d20\uff0c\u9700\u8981\u8ba1\u7b97\u6570\u7ec4\u7684\u4e2d\u95f4\u7d22\u5f15\uff1a int middleIdx = arr.length \/ 2; \u767b\u5f55\u540e\u590d\u5236 \u5bf9\u4e8e\u5076\u6570\u957f\u5ea6\u7684\u6570\u7ec4\uff0c\u4e2d\u95f4\u7d22\u5f15\u5c06\u5728\u4e24\u4e2a\u4e2d\u95f4\u5143\u7d20\u4e4b\u95f4\u3002 3. \u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4 \u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\u6765\u5b58\u50a8\u5220\u53bb\u4e2d\u95f4\u5143\u7d20\u540e\u7684\u6570\u7ec4\uff1a int[] newArr = new int[arr.length &#8211; 1]; \u767b\u5f55\u540e\u590d\u5236 4. \u590d\u5236\u5143\u7d20 \u5c06\u4e2d\u95f4\u5143\u7d20\u4e4b\u524d\u7684\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\u4e2d\uff1a for (int [&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-66277","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66277","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=66277"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66277\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}