{"id":64526,"date":"2025-05-03T17:18:30","date_gmt":"2025-05-03T09:18:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/64526\/"},"modified":"2025-05-03T17:18:30","modified_gmt":"2025-05-03T09:18:30","slug":"java%e6%80%8e%e4%b9%88%e8%be%93%e5%85%a5%e4%b8%80%e4%b8%aachar%e5%9e%8b%e6%95%b0%e7%bb%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/64526\/","title":{"rendered":"java\u600e\u4e48\u8f93\u5165\u4e00\u4e2achar\u578b\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u8981\u8f93\u5165\u4e00\u4e2a char \u578b\u6570\u7ec4\uff0c\u9700\u8981\uff1a1. \u58f0\u660e char \u6570\u7ec4\u6307\u5b9a\u5927\u5c0f\uff1b2. \u4f7f\u7528\u952e\u76d8\u8f93\u5165\u5b57\u7b26\u5e76\u4f9d\u6b21\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\uff1b3. \u5173\u95ed scanner \u5bf9\u8c61\u91ca\u653e\u8d44\u6e90\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/03\/2024110323342994486.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u8f93\u5165\u4e00\u4e2achar\u578b\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u8f93\u5165\u4e00\u4e2achar\u578b\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u7528 Java \u8f93\u5165\u4e00\u4e2a char \u578b\u6570\u7ec4<\/strong><\/p>\n<p>\u8981\u8f93\u5165\u4e00\u4e2a char \u578b\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u58f0\u660e char \u6570\u7ec4<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u58f0\u660e\u4e00\u4e2a char \u6570\u7ec4\u5e76\u6307\u5b9a\u5176\u5927\u5c0f\u3002\u4f8b\u5982\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>char[] chars = new char[10];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528\u952e\u76d8\u8f93\u5165<\/strong><\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u4f7f\u7528 Scanner \u7c7b\u4ece\u952e\u76d8\u8f93\u5165\u5b57\u7b26\u5e76\u5c06\u5176\u5b58\u50a8\u5728 char \u6570\u7ec4\u4e2d\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>Scanner scanner = new Scanner(System.in);\nfor (int i = 0; i &lt; chars.length; i++) {\n    chars[i] = scanner.next().charAt(0);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u5173\u95ed Scanner<\/strong><\/p>\n<p>\u8f93\u5165\u5b8c\u6210\u540e\uff0c\u5173\u95ed Scanner \u5bf9\u8c61\u4ee5\u91ca\u653e\u8d44\u6e90\u3002<\/p>\n<pre>scanner.close();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u793a\u4f8b\uff0c\u6f14\u793a\u4e86\u5982\u4f55\u8f93\u5165\u4e00\u4e2a char \u578b\u6570\u7ec4\uff1a<\/p>\n<pre>import java.util.Scanner;\n\npublic class Main {\n\n    public static void main(String[] args) {\n        \/\/ \u58f0\u660e char \u6570\u7ec4\n        char[] chars = new char[3];\n\n        \/\/ \u4ece\u952e\u76d8\u8f93\u5165\u5b57\u7b26\n        Scanner scanner = new Scanner(System.in);\n        for (int i = 0; i &lt; chars.length; i++) {\n            chars[i] = scanner.next().charAt(0);\n        }\n\n        \/\/ \u5173\u95ed Scanner\n        scanner.close();\n\n        \/\/ \u6253\u5370 char \u6570\u7ec4\n        for (char c : chars) {\n            System.out.println(c);\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u8f93\u5165\u4e00\u4e2achar\u578b\u6570\u7ec4\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\u8f93\u5165\u4e00\u4e2a char \u578b\u6570\u7ec4\uff0c\u9700\u8981\uff1a1. \u58f0\u660e char \u6570\u7ec4\u6307\u5b9a\u5927\u5c0f\uff1b2. \u4f7f\u7528\u952e\u76d8\u8f93\u5165\u5b57\u7b26\u5e76\u4f9d\u6b21\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\uff1b3. \u5173\u95ed scanner \u5bf9\u8c61\u91ca\u653e\u8d44\u6e90\u3002 \u5982\u4f55\u7528 Java \u8f93\u5165\u4e00\u4e2a char \u578b\u6570\u7ec4 \u8981\u8f93\u5165\u4e00\u4e2a char \u578b\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u58f0\u660e char \u6570\u7ec4 \u9996\u5148\uff0c\u58f0\u660e\u4e00\u4e2a char \u6570\u7ec4\u5e76\u6307\u5b9a\u5176\u5927\u5c0f\u3002\u4f8b\u5982\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b char[] chars = new char[10]; \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528\u952e\u76d8\u8f93\u5165 \u63a5\u4e0b\u6765\uff0c\u4f7f\u7528 Scanner \u7c7b\u4ece\u952e\u76d8\u8f93\u5165\u5b57\u7b26\u5e76\u5c06\u5176\u5b58\u50a8\u5728 char \u6570\u7ec4\u4e2d\u3002\u4f8b\u5982\uff1a Scanner scanner = new Scanner(System.in); for (int i = 0; i &lt; chars.length; i++) { chars[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-64526","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64526","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=64526"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64526\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=64526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=64526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=64526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}