{"id":37329,"date":"2024-11-26T08:59:29","date_gmt":"2024-11-26T00:59:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/37329\/"},"modified":"2024-11-26T08:59:29","modified_gmt":"2024-11-26T00:59:29","slug":"java%e4%b8%ad%e6%80%8e%e4%b9%88%e8%a1%a8%e7%a4%ba%e5%a4%9a%e7%bb%b4%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/37329\/","title":{"rendered":"java\u4e2d\u600e\u4e48\u8868\u793a\u591a\u7ef4\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u591a\u7ef4\u6570\u7ec4\u5728 java \u4e2d\u901a\u8fc7\u65b9\u62ec\u53f7\u8868\u793a\uff0c\u6bcf\u4e2a\u7ef4\u5ea6\u5bf9\u5e94\u4e00\u5bf9\u65b9\u62ec\u53f7\u3002\u58f0\u660e\u591a\u7ef4\u6570\u7ec4\u65f6\u9700\u6307\u5b9a\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u957f\u5ea6\uff0c\u53ef\u901a\u8fc7 new \u5173\u952e\u5b57\u6216\u5927\u62ec\u53f7\u8bed\u6cd5\u521d\u59cb\u5316\u5143\u7d20\u3002\u6bcf\u4e2a\u7ef4\u5ea6\u957f\u5ea6\u53ef\u901a\u8fc7 length \u5c5e\u6027\u83b7\u53d6\u3002\u5d4c\u5957\u5faa\u73af\u53ef\u7528\u4e8e\u904d\u5386\u591a\u7ef4\u6570\u7ec4\uff0c\u8bbf\u95ee\u6bcf\u4e2a\u5143\u7d20\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111304003349430.jpg\" class=\"aligncenter\" title=\"java\u4e2d\u600e\u4e48\u8868\u793a\u591a\u7ef4\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u4e2d\u600e\u4e48\u8868\u793a\u591a\u7ef4\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u591a\u7ef4\u6570\u7ec4\u5728 Java \u4e2d\u7684\u8868\u793a<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u591a\u7ef4\u6570\u7ec4\u662f\u901a\u8fc7\u4f7f\u7528\u65b9\u62ec\u53f7\u6765\u8868\u793a\u7684\uff0c\u6bcf\u4e2a\u7ef4\u5ea6\u90fd\u7528\u4e00\u5bf9\u65b9\u62ec\u53f7\u62ec\u8d77\u6765\u3002\u6570\u7ec4\u7684\u6bcf\u4e2a\u7ef4\u5ea6\u90fd\u6709\u4e00\u4e2a\u957f\u5ea6\uff0c\u8868\u793a\u8be5\u7ef4\u5ea6\u4e2d\u5143\u7d20\u7684\u6570\u91cf\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u58f0\u660e\uff1a<\/p>\n<pre>int[][] myArray = new int[3][4];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u58f0\u660e\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b 3 \u884c\u548c 4 \u5217\u7684\u4e8c\u7ef4\u6570\u7ec4\u3002\u6bcf\u4e2a\u5143\u7d20\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u8fdb\u884c\u8bbf\u95ee\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>myArray[row][column]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d row \u662f\u884c\u7684\u7d22\u5f15\uff0ccolumn \u662f\u5217\u7684\u7d22\u5f15\u3002<\/p>\n<p><strong>\u58f0\u660e\u548c\u521d\u59cb\u5316\u591a\u7ef4\u6570\u7ec4<\/strong><\/p>\n<p>\u591a\u7ef4\u6570\u7ec4\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 new \u5173\u952e\u5b57\u548c\u6307\u5b9a\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u957f\u5ea6\u6765\u58f0\u660e\u3002\u4e5f\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u5927\u62ec\u53f7\u8bed\u6cd5\u6765\u521d\u59cb\u5316\u6570\u7ec4\u5143\u7d20\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u58f0\u660e\u5e76\u521d\u59cb\u5316\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\uff1a<\/p>\n<pre>int[][] myArray = {\n    {1, 2, 3, 4},\n    {5, 6, 7, 8},\n    {9, 10, 11, 12}\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u591a\u7ef4\u6570\u7ec4\u7684\u957f\u5ea6<\/strong><\/p>\n<p>\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u957f\u5ea6\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 length \u5c5e\u6027\u6765\u83b7\u53d6\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u83b7\u53d6\u4e8c\u7ef4\u6570\u7ec4\u7684\u884c\u6570\uff1a<\/p>\n<pre>int numRows = myArray.length;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u591a\u7ef4\u6570\u7ec4\u7684\u904d\u5386<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u6765\u904d\u5386\u591a\u7ef4\u6570\u7ec4\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u904d\u5386\u4e8c\u7ef4\u6570\u7ec4\u5e76\u6253\u5370\u6bcf\u4e2a\u5143\u7d20\uff1a<\/p>\n<pre>for (int i = 0; i &lt; myArray.length; i++) {\n    for (int j = 0; j &lt; myArray[i].length; j++) {\n        System.out.print(myArray[i][j] + \" \");\n    }\n    System.out.println();\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u4e2d\u600e\u4e48\u8868\u793a\u591a\u7ef4\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>\u591a\u7ef4\u6570\u7ec4\u5728 java \u4e2d\u901a\u8fc7\u65b9\u62ec\u53f7\u8868\u793a\uff0c\u6bcf\u4e2a\u7ef4\u5ea6\u5bf9\u5e94\u4e00\u5bf9\u65b9\u62ec\u53f7\u3002\u58f0\u660e\u591a\u7ef4\u6570\u7ec4\u65f6\u9700\u6307\u5b9a\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u957f\u5ea6\uff0c\u53ef\u901a\u8fc7 new \u5173\u952e\u5b57\u6216\u5927\u62ec\u53f7\u8bed\u6cd5\u521d\u59cb\u5316\u5143\u7d20\u3002\u6bcf\u4e2a\u7ef4\u5ea6\u957f\u5ea6\u53ef\u901a\u8fc7 length \u5c5e\u6027\u83b7\u53d6\u3002\u5d4c\u5957\u5faa\u73af\u53ef\u7528\u4e8e\u904d\u5386\u591a\u7ef4\u6570\u7ec4\uff0c\u8bbf\u95ee\u6bcf\u4e2a\u5143\u7d20\u3002 \u591a\u7ef4\u6570\u7ec4\u5728 Java \u4e2d\u7684\u8868\u793a \u5728 Java \u4e2d\uff0c\u591a\u7ef4\u6570\u7ec4\u662f\u901a\u8fc7\u4f7f\u7528\u65b9\u62ec\u53f7\u6765\u8868\u793a\u7684\uff0c\u6bcf\u4e2a\u7ef4\u5ea6\u90fd\u7528\u4e00\u5bf9\u65b9\u62ec\u53f7\u62ec\u8d77\u6765\u3002\u6570\u7ec4\u7684\u6bcf\u4e2a\u7ef4\u5ea6\u90fd\u6709\u4e00\u4e2a\u957f\u5ea6\uff0c\u8868\u793a\u8be5\u7ef4\u5ea6\u4e2d\u5143\u7d20\u7684\u6570\u91cf\u3002 \u4f8b\u5982\uff0c\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u58f0\u660e\uff1a int[][] myArray = new int[3][4]; \u767b\u5f55\u540e\u590d\u5236 \u8be5\u58f0\u660e\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b 3 \u884c\u548c 4 \u5217\u7684\u4e8c\u7ef4\u6570\u7ec4\u3002\u6bcf\u4e2a\u5143\u7d20\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u8fdb\u884c\u8bbf\u95ee\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b myArray[row][column] \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d row \u662f\u884c\u7684\u7d22\u5f15\uff0ccolumn \u662f\u5217\u7684\u7d22\u5f15\u3002 \u58f0\u660e\u548c\u521d\u59cb\u5316\u591a\u7ef4\u6570\u7ec4 \u591a\u7ef4\u6570\u7ec4\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 new \u5173\u952e\u5b57\u548c\u6307\u5b9a\u6bcf\u4e2a\u7ef4\u5ea6\u7684\u957f\u5ea6\u6765\u58f0\u660e\u3002\u4e5f\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u5927\u62ec\u53f7\u8bed\u6cd5\u6765\u521d\u59cb\u5316\u6570\u7ec4\u5143\u7d20\u3002 \u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u58f0\u660e\u5e76\u521d\u59cb\u5316\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\uff1a int[][] myArray = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12} }; \u767b\u5f55\u540e\u590d\u5236 [&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-37329","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37329","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=37329"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37329\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=37329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=37329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=37329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}