{"id":34857,"date":"2024-11-26T08:56:10","date_gmt":"2024-11-26T00:56:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/34857\/"},"modified":"2024-11-26T08:56:10","modified_gmt":"2024-11-26T00:56:10","slug":"java%e5%80%92%e6%8e%92%e4%b8%80%e4%b8%aa%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/34857\/","title":{"rendered":"java\u5012\u6392\u4e00\u4e2a\u6570\u7ec4\u600e\u4e48\u5199"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u5012\u6392\u6570\u7ec4\u7684\u65b9\u6cd5\u662f\uff1a\u5faa\u73af\u6570\u7ec4\u4ece\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5f00\u59cb\u904d\u5386\u3002\u4ea4\u6362\u5143\u7d20\uff0c\u5c06\u6bcf\u4e2a\u5143\u7d20\u4e0e\u6570\u7ec4\u5f00\u5934\u7684\u4e00\u4e2a\u5143\u7d20\u4ea4\u6362\u3002\u91cd\u590d\u4ea4\u6362\uff0c\u76f4\u81f3\u6240\u6709\u5143\u7d20\u90fd\u88ab\u4ea4\u6362\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/03\/2024110304424952474.jpg\" class=\"aligncenter\" title=\"java\u5012\u6392\u4e00\u4e2a\u6570\u7ec4\u600e\u4e48\u5199\u63d2\u56fe\" alt=\"java\u5012\u6392\u4e00\u4e2a\u6570\u7ec4\u600e\u4e48\u5199\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5012\u6392 Java \u6570\u7ec4<\/strong><\/p>\n<p>\u5012\u6392\u6570\u7ec4\u662f\u6307\u5c06\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u987a\u5e8f\u4ece\u540e\u5f80\u524d\u91cd\u65b0\u3002Java \u4e2d\u5012\u6392\u6570\u7ec4\u7684\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a<\/p>\n<p><strong>1. \u5faa\u73af\u6570\u7ec4<\/strong><\/p>\n<p>\u4ece\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u904d\u5386\u6574\u4e2a\u6570\u7ec4\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>2. \u4ea4\u6362\u5143\u7d20<\/strong><\/p>\n<p>\u5bf9\u4e8e\u6bcf\u4e2a\u5143\u7d20\uff0c\u5c06\u5176\u4e0e\u6570\u7ec4\u5f00\u5934\u7684\u4e00\u4e2a\u5143\u7d20\u8fdb\u884c\u4ea4\u6362\u3002<\/p>\n<p><strong>3. \u7ee7\u7eed\u4ea4\u6362<\/strong><\/p>\n<p>\u91cd\u590d\u6b65\u9aa4 2\uff0c\u76f4\u5230\u6240\u6709\u5143\u7d20\u90fd\u88ab\u4ea4\u6362\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>public static void main(String[] args) {\n    int[] arr = {1, 2, 3, 4, 5};\n\n    \/\/ \u5faa\u73af\u6570\u7ec4\n    for (int i = arr.length - 1; i &gt;= 0; i--) {\n        \/\/ \u4ea4\u6362\u5143\u7d20\n        int temp = arr[i];\n        arr[i] = arr[0];\n        arr[0] = temp;\n    }\n\n    \/\/ \u8f93\u51fa\u5012\u6392\u540e\u7684\u6570\u7ec4\n    System.out.println(Arrays.toString(arr));\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre>[5, 4, 3, 2, 1]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65f6\u95f4\u590d\u6742\u5ea6\uff1a<\/strong><\/p>\n<p>\u4e0a\u8ff0\u65b9\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\uff0c\u5176\u4e2d n \u662f\u6570\u7ec4\u7684\u957f\u5ea6\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u5012\u6392\u4e00\u4e2a\u6570\u7ec4\u600e\u4e48\u5199\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\u5012\u6392\u6570\u7ec4\u7684\u65b9\u6cd5\u662f\uff1a\u5faa\u73af\u6570\u7ec4\u4ece\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5f00\u59cb\u904d\u5386\u3002\u4ea4\u6362\u5143\u7d20\uff0c\u5c06\u6bcf\u4e2a\u5143\u7d20\u4e0e\u6570\u7ec4\u5f00\u5934\u7684\u4e00\u4e2a\u5143\u7d20\u4ea4\u6362\u3002\u91cd\u590d\u4ea4\u6362\uff0c\u76f4\u81f3\u6240\u6709\u5143\u7d20\u90fd\u88ab\u4ea4\u6362\u3002 \u5982\u4f55\u5012\u6392 Java \u6570\u7ec4 \u5012\u6392\u6570\u7ec4\u662f\u6307\u5c06\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u987a\u5e8f\u4ece\u540e\u5f80\u524d\u91cd\u65b0\u3002Java \u4e2d\u5012\u6392\u6570\u7ec4\u7684\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a 1. \u5faa\u73af\u6570\u7ec4 \u4ece\u6570\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u904d\u5386\u6574\u4e2a\u6570\u7ec4\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b 2. \u4ea4\u6362\u5143\u7d20 \u5bf9\u4e8e\u6bcf\u4e2a\u5143\u7d20\uff0c\u5c06\u5176\u4e0e\u6570\u7ec4\u5f00\u5934\u7684\u4e00\u4e2a\u5143\u7d20\u8fdb\u884c\u4ea4\u6362\u3002 3. \u7ee7\u7eed\u4ea4\u6362 \u91cd\u590d\u6b65\u9aa4 2\uff0c\u76f4\u5230\u6240\u6709\u5143\u7d20\u90fd\u88ab\u4ea4\u6362\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a public static void main(String[] args) { int[] arr = {1, 2, 3, 4, 5}; \/\/ \u5faa\u73af\u6570\u7ec4 for (int i = arr.length &#8211; 1; i &gt;= 0; i&#8211;) { \/\/ \u4ea4\u6362\u5143\u7d20 int temp = arr[i]; arr[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-34857","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34857","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=34857"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34857\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=34857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=34857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=34857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}