{"id":35055,"date":"2024-11-26T10:01:44","date_gmt":"2024-11-26T02:01:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/35055\/"},"modified":"2024-11-26T10:01:44","modified_gmt":"2024-11-26T02:01:44","slug":"java%e6%80%8e%e4%b9%88%e7%94%a8%e4%ba%8c%e7%bb%b4%e6%95%b0%e7%bb%84%e7%94%bb%e5%9c%b0%e5%9b%be","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/35055\/","title":{"rendered":"Java\u600e\u4e48\u7528\u4e8c\u7ef4\u6570\u7ec4\u753b\u5730\u56fe"},"content":{"rendered":"<blockquote><p>\n  \u4e8c\u7ef4\u6570\u7ec4\u53ef\u4ee5\u7528\u4e8e\u7ed8\u5236\u5730\u56fe\uff0c\u901a\u8fc7\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\u5e76\u521d\u59cb\u5316\u6570\u7ec4\u5143\u7d20\u4e3a\u7279\u5b9a\u5b57\u7b26\uff08\u5982 &#8216;.&#8217; \u8868\u793a\u5f00\u653e\u7a7a\u95f4\u6216 &#8216;#&#8217; \u8868\u793a\u969c\u788d\u7269\uff09\uff0c\u53ef\u4ee5\u5b58\u50a8\u7f51\u683c\u4e2d\u7684\u5143\u7d20\uff0c\u8bbe\u7f6e\u5730\u56fe\u5bf9\u8c61\uff0c\u904d\u5386\u6570\u7ec4\u5e76\u6253\u5370\u6bcf\u4e2a\u5b57\u7b26\uff0c\u4f7f\u7528\u6807\u51c6\u8f93\u51fa\u5c06\u5730\u56fe\u6253\u5370\u5230\u63a7\u5236\u53f0\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/03\/2024110309093411989.jpg\" class=\"aligncenter\" title=\"Java\u600e\u4e48\u7528\u4e8c\u7ef4\u6570\u7ec4\u753b\u5730\u56fe\u63d2\u56fe\" alt=\"Java\u600e\u4e48\u7528\u4e8c\u7ef4\u6570\u7ec4\u753b\u5730\u56fe\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u753b\u5730\u56fe<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong>\u5982\u4f55\u4f7f\u7528 Java \u4e2d\u7684\u4e8c\u7ef4\u6570\u7ec4\u6765\u7ed8\u5236\u5730\u56fe\uff1f<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong><\/p>\n<p>\u4e8c\u7ef4\u6570\u7ec4\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u53ef\u4ee5\u5b58\u50a8\u7f51\u683c\u4e2d\u7684\u5143\u7d20\u3002\u6bcf\u4e2a\u5143\u7d20\u7531\u5176\u884c\u548c\u5217\u4f4d\u7f6e\u6807\u8bc6\u3002\u8981\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u7ed8\u5236\u5730\u56fe\uff0c\u53ef\u4ee5\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>1. \u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\uff1a<\/strong><\/p>\n<ul>\n<li><strong>char[][] map = new charheight;<\/strong><\/li>\n<li>\u5c06\u5730\u56fe\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u6784\u9020\u51fd\u6570\u3002<\/li>\n<\/ul>\n<p><strong>2. \u521d\u59cb\u5316\u6570\u7ec4\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528\u5faa\u73af\u521d\u59cb\u5316\u6570\u7ec4\u5143\u7d20\u4e3a\u7279\u5b9a\u5b57\u7b26\uff0c\u4f8b\u5982 &#8216;.&#8217;\uff08\u8868\u793a\u5f00\u653e\u7a7a\u95f4\uff09\u6216 &#8216;#&#8217;\uff08\u8868\u793a\u969c\u788d\u7269\uff09\u3002<\/li>\n<\/ul>\n<p><strong>3. \u8bbe\u7f6e\u5730\u56fe\u5bf9\u8c61\uff1a<\/strong><\/p>\n<ul>\n<li>\n<p>\u521b\u5efa\u4e00\u4e2a\u7c7b\u6765\u8868\u793a\u5730\u56fe\uff0c\u5176\u4e2d\u5305\u542b\u4e8c\u7ef4\u6570\u7ec4\u548c\u4e00\u4e9b\u76f8\u5173\u65b9\u6cd5\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li> <strong>getMap()<\/strong>\uff1a\u8fd4\u56de\u4e8c\u7ef4\u6570\u7ec4\u3002<\/li>\n<li> <strong>getSize()<\/strong>\uff1a\u8fd4\u56de\u5730\u56fe\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u3002<\/li>\n<li> <strong>setChar(int row, int col, char c)<\/strong>\uff1a\u8bbe\u7f6e\u7279\u5b9a\u4f4d\u7f6e\u7684\u5b57\u7b26\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>4. \u7ed8\u5236\u5730\u56fe\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u904d\u5386\u4e8c\u7ef4\u6570\u7ec4\u5e76\u6253\u5370\u6bcf\u4e2a\u5b57\u7b26\u3002<\/li>\n<li>\u5bf9\u4e8e\u6bcf\u4e2a\u4f4d\u7f6e\uff0c\u4f7f\u7528 if \u8bed\u53e5\u68c0\u67e5\u5b57\u7b26\u662f\u5426\u8868\u793a\u5f00\u653e\u7a7a\u95f4\u6216\u969c\u788d\u7269\uff0c\u7136\u540e\u76f8\u5e94\u5730\u6253\u5370 &#8216;.&#8217; \u6216 &#8216;#&#8217;.<\/li>\n<\/ul>\n<p><strong>5. \u663e\u793a\u5730\u56fe\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528\u6807\u51c6\u8f93\u51fa\uff08\u4f8b\u5982 System.out.println\uff09\u5c06\u5730\u56fe\u6253\u5370\u5230\u63a7\u5236\u53f0\u6216\u5176\u4ed6\u8f93\u51fa\u8bbe\u5907\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>public class Map {\n\n    private char[][] map;\n\n    public Map(int height, int width) {\n        map = new char[height][width];\n    }\n\n    public void initMap() {\n        for (int i = 0; i &lt; height; i++) {\n            for (int j = 0; j &lt; width; j++) {\n                map[i][j] = '.';\n            }\n        }\n    }\n\n    public void setChar(int row, int col, char c) {\n        map[row][col] = c;\n    }\n\n    public void drawMap() {\n        for (int i = 0; i &lt; height; i++) {\n            for (int j = 0; j &lt; width; j++) {\n                System.out.print(map[i][j]);\n            }\n            System.out.println();\n        }\n    }\n}\n\npublic class Main {\n\n    public static void main(String[] args) {\n        Map map = new Map(10, 10);\n        map.initMap();\n        map.setChar(5, 5, '#');\n        map.drawMap();\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJava\u600e\u4e48\u7528\u4e8c\u7ef4\u6570\u7ec4\u753b\u5730\u56fe\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>\u4e8c\u7ef4\u6570\u7ec4\u53ef\u4ee5\u7528\u4e8e\u7ed8\u5236\u5730\u56fe\uff0c\u901a\u8fc7\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\u5e76\u521d\u59cb\u5316\u6570\u7ec4\u5143\u7d20\u4e3a\u7279\u5b9a\u5b57\u7b26\uff08\u5982 &#8216;.&#8217; \u8868\u793a\u5f00\u653e\u7a7a\u95f4\u6216 &#8216;#&#8217; \u8868\u793a\u969c\u788d\u7269\uff09\uff0c\u53ef\u4ee5\u5b58\u50a8\u7f51\u683c\u4e2d\u7684\u5143\u7d20\uff0c\u8bbe\u7f6e\u5730\u56fe\u5bf9\u8c61\uff0c\u904d\u5386\u6570\u7ec4\u5e76\u6253\u5370\u6bcf\u4e2a\u5b57\u7b26\uff0c\u4f7f\u7528\u6807\u51c6\u8f93\u51fa\u5c06\u5730\u56fe\u6253\u5370\u5230\u63a7\u5236\u53f0\u3002 Java \u4e2d\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u753b\u5730\u56fe \u95ee\u9898\uff1a\u5982\u4f55\u4f7f\u7528 Java \u4e2d\u7684\u4e8c\u7ef4\u6570\u7ec4\u6765\u7ed8\u5236\u5730\u56fe\uff1f \u56de\u7b54\uff1a \u4e8c\u7ef4\u6570\u7ec4\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u53ef\u4ee5\u5b58\u50a8\u7f51\u683c\u4e2d\u7684\u5143\u7d20\u3002\u6bcf\u4e2a\u5143\u7d20\u7531\u5176\u884c\u548c\u5217\u4f4d\u7f6e\u6807\u8bc6\u3002\u8981\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u7ed8\u5236\u5730\u56fe\uff0c\u53ef\u4ee5\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b 1. \u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\uff1a char[][] map = new charheight; \u5c06\u5730\u56fe\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u6784\u9020\u51fd\u6570\u3002 2. \u521d\u59cb\u5316\u6570\u7ec4\uff1a \u4f7f\u7528\u5faa\u73af\u521d\u59cb\u5316\u6570\u7ec4\u5143\u7d20\u4e3a\u7279\u5b9a\u5b57\u7b26\uff0c\u4f8b\u5982 &#8216;.&#8217;\uff08\u8868\u793a\u5f00\u653e\u7a7a\u95f4\uff09\u6216 &#8216;#&#8217;\uff08\u8868\u793a\u969c\u788d\u7269\uff09\u3002 3. \u8bbe\u7f6e\u5730\u56fe\u5bf9\u8c61\uff1a \u521b\u5efa\u4e00\u4e2a\u7c7b\u6765\u8868\u793a\u5730\u56fe\uff0c\u5176\u4e2d\u5305\u542b\u4e8c\u7ef4\u6570\u7ec4\u548c\u4e00\u4e9b\u76f8\u5173\u65b9\u6cd5\uff0c\u4f8b\u5982\uff1a getMap()\uff1a\u8fd4\u56de\u4e8c\u7ef4\u6570\u7ec4\u3002 getSize()\uff1a\u8fd4\u56de\u5730\u56fe\u7684\u9ad8\u5ea6\u548c\u5bbd\u5ea6\u3002 setChar(int row, int col, char c)\uff1a\u8bbe\u7f6e\u7279\u5b9a\u4f4d\u7f6e\u7684\u5b57\u7b26\u3002 4. \u7ed8\u5236\u5730\u56fe\uff1a \u4f7f\u7528\u5d4c\u5957\u5faa\u73af\u904d\u5386\u4e8c\u7ef4\u6570\u7ec4\u5e76\u6253\u5370\u6bcf\u4e2a\u5b57\u7b26\u3002 \u5bf9\u4e8e\u6bcf\u4e2a\u4f4d\u7f6e\uff0c\u4f7f\u7528 if \u8bed\u53e5\u68c0\u67e5\u5b57\u7b26\u662f\u5426\u8868\u793a\u5f00\u653e\u7a7a\u95f4\u6216\u969c\u788d\u7269\uff0c\u7136\u540e\u76f8\u5e94\u5730\u6253\u5370 &#8216;.&#8217; \u6216 &#8216;#&#8217;. 5. \u663e\u793a\u5730\u56fe\uff1a \u4f7f\u7528\u6807\u51c6\u8f93\u51fa\uff08\u4f8b\u5982 System.out.println\uff09\u5c06\u5730\u56fe\u6253\u5370\u5230\u63a7\u5236\u53f0\u6216\u5176\u4ed6\u8f93\u51fa\u8bbe\u5907\u3002 \u793a\u4f8b\u4ee3\u7801\uff1a public class Map { [&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-35055","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35055","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=35055"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/35055\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=35055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=35055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=35055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}