{"id":66944,"date":"2025-05-03T13:13:21","date_gmt":"2025-05-03T05:13:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66944\/"},"modified":"2025-05-03T13:13:21","modified_gmt":"2025-05-03T05:13:21","slug":"java%e4%ba%8c%e7%bb%b4%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e5%a2%9e%e5%8a%a0%e6%95%b0%e6%8d%ae-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66944\/","title":{"rendered":"java\u4e8c\u7ef4\u6570\u7ec4\u600e\u4e48\u589e\u52a0\u6570\u636e"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u7684\u4e8c\u7ef4\u6570\u7ec4\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u6dfb\u52a0\u6570\u636e\uff1a\u58f0\u660e\u6570\u7ec4\u5e76\u6307\u5b9a\u884c\u6570\u548c\u5217\u6570\u3002\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u8bbf\u95ee\u5e76\u8bbe\u7f6e\u6570\u7ec4\u5143\u7d20\u3002\u8981\u6dfb\u52a0\u5143\u7d20\u5230\u6700\u540e\u4e00\u5217\uff0c\u8bf7\u4f7f\u7528\u5176 length \u5b57\u6bb5\u3002\u8981\u6dfb\u52a0\u5143\u7d20\u5230\u6700\u540e\u4e00\u884c\uff0c\u8bf7\u4f7f\u7528\u6570\u7ec4\u7684 length \u5b57\u6bb5\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/17\/2024111720032165125.jpg\" class=\"aligncenter\" title=\"java\u4e8c\u7ef4\u6570\u7ec4\u600e\u4e48\u589e\u52a0\u6570\u636e\u63d2\u56fe\" alt=\"java\u4e8c\u7ef4\u6570\u7ec4\u600e\u4e48\u589e\u52a0\u6570\u636e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4e3a Java \u4e8c\u7ef4\u6570\u7ec4\u6dfb\u52a0\u6570\u636e<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u4e8c\u7ef4\u6570\u7ec4\u662f\u4e00\u79cd\u5305\u542b\u56fa\u5b9a\u884c\u6570\u548c\u5217\u6570\u7684\u5143\u7d20\u96c6\u5408\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u4e3a\u4e8c\u7ef4\u6570\u7ec4\u6dfb\u52a0\u6570\u636e\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u58f0\u660e\u4e8c\u7ef4\u6570\u7ec4\uff1a<\/strong><\/p>\n<pre>int[][] myArray = new int[rows][columns];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff1a<\/strong><br \/>\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff0c\u5176\u4e2d\u5916\u90e8\u5faa\u73af\u904d\u5386\u884c\uff0c\u5185\u90e8\u5faa\u73af\u904d\u5386\u5217\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>for (int i = 0; i &lt; rows; i++) {\n  for (int j = 0; j &lt; columns; j++) {\n \/\/ \u8bbf\u95ee myArray[i][j]\n  }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u8bbe\u7f6e\u6570\u7ec4\u5143\u7d20\uff1a<\/strong><br \/>\u4f7f\u7528\u8d4b\u503c\u8fd0\u7b97\u7b26\u4e3a\u6570\u7ec4\u5143\u7d20\u8bbe\u7f6e\u503c\uff1a<\/p>\n<pre>myArray[i][j] = value;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li><strong>\u7279\u6b8a\u7528\u6cd5\uff1a<\/strong><\/li>\n<li>\n<p><strong>\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\u5230\u6700\u540e\u4e00\u5217\uff1a<\/strong>\u60a8\u53ef\u4ee5\u8bbf\u95ee\u6700\u540e\u4e00\u5217\u5e76\u4f7f\u7528\u5176 length \u5b57\u6bb5\u6765\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>myArray[i][myArray[i].length] = value;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\u5230\u6700\u540e\u4e00\u884c\uff1a<\/strong>\u4f7f\u7528\u6570\u7ec4\u7684 length \u5b57\u6bb5\u6765\u8bbf\u95ee\u6700\u540e\u4e00\u884c\u5e76\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>myArray[myArray.length][j] = value;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<pre>int[][] myArray = new int[3][4];\n\n\/\/ \u8bbf\u95ee\u548c\u8bbe\u7f6e\u5143\u7d20\nfor (int i = 0; i &lt; 3; i++) {\n  for (int j = 0; j &lt; 4; j++) {\n    myArray[i][j] = i + j;\n  }\n}\n\n\/\/ \u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\u5230\u6700\u540e\u4e00\u5217\nmyArray[1][myArray[1].length] = 10;\n\n\/\/ \u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\u5230\u6700\u540e\u4e00\u884c\nmyArray[myArray.length][2] = 20;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u4e8c\u7ef4\u6570\u7ec4\u600e\u4e48\u589e\u52a0\u6570\u636e\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>java \u4e2d\u7684\u4e8c\u7ef4\u6570\u7ec4\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u6dfb\u52a0\u6570\u636e\uff1a\u58f0\u660e\u6570\u7ec4\u5e76\u6307\u5b9a\u884c\u6570\u548c\u5217\u6570\u3002\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u8bbf\u95ee\u5e76\u8bbe\u7f6e\u6570\u7ec4\u5143\u7d20\u3002\u8981\u6dfb\u52a0\u5143\u7d20\u5230\u6700\u540e\u4e00\u5217\uff0c\u8bf7\u4f7f\u7528\u5176 length \u5b57\u6bb5\u3002\u8981\u6dfb\u52a0\u5143\u7d20\u5230\u6700\u540e\u4e00\u884c\uff0c\u8bf7\u4f7f\u7528\u6570\u7ec4\u7684 length \u5b57\u6bb5\u3002 \u5982\u4f55\u4e3a Java \u4e8c\u7ef4\u6570\u7ec4\u6dfb\u52a0\u6570\u636e \u5728 Java \u4e2d\uff0c\u4e8c\u7ef4\u6570\u7ec4\u662f\u4e00\u79cd\u5305\u542b\u56fa\u5b9a\u884c\u6570\u548c\u5217\u6570\u7684\u5143\u7d20\u96c6\u5408\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u4e3a\u4e8c\u7ef4\u6570\u7ec4\u6dfb\u52a0\u6570\u636e\uff1a \u58f0\u660e\u4e8c\u7ef4\u6570\u7ec4\uff1a int[][] myArray = new int[rows][columns]; \u767b\u5f55\u540e\u590d\u5236 \u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff1a\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff0c\u5176\u4e2d\u5916\u90e8\u5faa\u73af\u904d\u5386\u884c\uff0c\u5185\u90e8\u5faa\u73af\u904d\u5386\u5217\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b for (int i = 0; i &lt; rows; i++) { for (int j = 0; j &lt; columns; j++) { \/\/ \u8bbf\u95ee myArray[i][j] } } \u767b\u5f55\u540e\u590d\u5236 \u8bbe\u7f6e\u6570\u7ec4\u5143\u7d20\uff1a\u4f7f\u7528\u8d4b\u503c\u8fd0\u7b97\u7b26\u4e3a\u6570\u7ec4\u5143\u7d20\u8bbe\u7f6e\u503c\uff1a myArray[i][j] = value; \u767b\u5f55\u540e\u590d\u5236 \u7279\u6b8a\u7528\u6cd5\uff1a \u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\u5230\u6700\u540e\u4e00\u5217\uff1a\u60a8\u53ef\u4ee5\u8bbf\u95ee\u6700\u540e\u4e00\u5217\u5e76\u4f7f\u7528\u5176 length [&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-66944","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66944","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=66944"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66944\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}