{"id":39119,"date":"2024-11-26T08:07:03","date_gmt":"2024-11-26T00:07:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/39119\/"},"modified":"2024-11-26T08:07:03","modified_gmt":"2024-11-26T00:07:03","slug":"java%e5%ad%97%e7%ac%a6%e6%80%8e%e4%b9%88%e8%be%93%e5%85%a5%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/39119\/","title":{"rendered":"java\u5b57\u7b26\u600e\u4e48\u8f93\u5165\u5b57\u7b26\u4e32\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\uff0c\u4f7f\u7528\u5b57\u7b26\u4e32\u6570\u7ec4\u8f93\u5165\u5b57\u7b26\u6709\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528 scanner \u7c7b\uff1a\u521d\u59cb\u5316 scanner \u5bf9\u8c61\uff0c\u901a\u8fc7 next() \u65b9\u6cd5\u9010\u4e2a\u8bfb\u53d6\u5b57\u7b26\u5230\u6570\u7ec4\u3002\u4f7f\u7528 bufferedreader \u7c7b\uff1a\u521d\u59cb\u5316 bufferedreader \u5bf9\u8c61\uff0c\u901a\u8fc7 readline() \u548c split() \u65b9\u6cd5\u5c06\u8f93\u5165\u884c\u62c6\u5206\u4e3a\u5b57\u7b26\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111604154044564.jpg\" class=\"aligncenter\" title=\"java\u5b57\u7b26\u600e\u4e48\u8f93\u5165\u5b57\u7b26\u4e32\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u5b57\u7b26\u600e\u4e48\u8f93\u5165\u5b57\u7b26\u4e32\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Java \u8f93\u5165\u5b57\u7b26\uff1f<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u4f7f\u7528\u5b57\u7b26\u4e32\u6570\u7ec4\u8f93\u5165\u5b57\u7b26\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528 Scanner \u7c7b<\/strong><\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ol>\n<li>\u521b\u5efa\u4e00\u4e2a Scanner \u5bf9\u8c61\uff0c\u5e76\u5c06\u5176\u521d\u59cb\u5316\u4e3a System.in\u3002<\/li>\n<li>\u4f7f\u7528 Scanner.next() \u65b9\u6cd5\u4ece\u63a7\u5236\u53f0\u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26\u3002<\/li>\n<li>\u5c06\u5b57\u7b26\u6dfb\u52a0\u5230\u5b57\u7b26\u4e32\u6570\u7ec4\u4e2d\u3002<\/li>\n<li>\u91cd\u590d\u6b65\u9aa4 2-3\uff0c\u76f4\u5230\u8f93\u5165\u6240\u6709\u6240\u9700\u7684\u5b57\u7b26\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>import java.util.Scanner;\n\npublic class InputCharactersToArray {\n\n    public static void main(String[] args) {\n        Scanner input = new Scanner(System.in);\n        String[] characters = new String[5];\n\n        for (int i = 0; i &lt; characters.length; i++) {\n            characters[i] = input.next();\n        }\n\n        \/\/ \u8f93\u51fa\u5b57\u7b26\u6570\u7ec4\u4e2d\u7684\u5b57\u7b26\n        for (String character : characters) {\n            System.out.println(character);\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528 BufferedReader \u7c7b<\/strong><\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ol>\n<li>\u521b\u5efa\u4e00\u4e2a BufferedReader \u5bf9\u8c61\uff0c\u5e76\u5c06\u5176\u521d\u59cb\u5316\u4e3a InputStreamReader(System.in)\u3002<\/li>\n<li>\u4f7f\u7528 BufferedReader.readLine() \u65b9\u6cd5\u4ece\u63a7\u5236\u53f0\u8bfb\u53d6\u4e00\u884c\u5b57\u7b26\u3002<\/li>\n<li>\u5c06\u8f93\u5165\u884c\u6309\u5b57\u7b26\u62c6\u5206\uff0c\u5e76\u5c06\u5b57\u7b26\u6dfb\u52a0\u5230\u5b57\u7b26\u4e32\u6570\u7ec4\u4e2d\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class InputCharactersToArray {\n\n    public static void main(String[] args) {\n        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n        String[] characters = new String[5];\n\n        try {\n            String line = input.readLine();\n            characters = line.split(\"\");\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n\n        \/\/ \u8f93\u51fa\u5b57\u7b26\u6570\u7ec4\u4e2d\u7684\u5b57\u7b26\n        for (String character : characters) {\n            System.out.println(character);\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u5b57\u7b26\u600e\u4e48\u8f93\u5165\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>\u5728 java \u4e2d\uff0c\u4f7f\u7528\u5b57\u7b26\u4e32\u6570\u7ec4\u8f93\u5165\u5b57\u7b26\u6709\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528 scanner \u7c7b\uff1a\u521d\u59cb\u5316 scanner \u5bf9\u8c61\uff0c\u901a\u8fc7 next() \u65b9\u6cd5\u9010\u4e2a\u8bfb\u53d6\u5b57\u7b26\u5230\u6570\u7ec4\u3002\u4f7f\u7528 bufferedreader \u7c7b\uff1a\u521d\u59cb\u5316 bufferedreader \u5bf9\u8c61\uff0c\u901a\u8fc7 readline() \u548c split() \u65b9\u6cd5\u5c06\u8f93\u5165\u884c\u62c6\u5206\u4e3a\u5b57\u7b26\u6570\u7ec4\u3002 \u5982\u4f55\u4f7f\u7528 Java \u8f93\u5165\u5b57\u7b26\uff1f \u5728 Java \u4e2d\uff0c\u4f7f\u7528\u5b57\u7b26\u4e32\u6570\u7ec4\u8f93\u5165\u5b57\u7b26\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a \u65b9\u6cd5 1\uff1a\u4f7f\u7528 Scanner \u7c7b \u6b65\u9aa4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u521b\u5efa\u4e00\u4e2a Scanner \u5bf9\u8c61\uff0c\u5e76\u5c06\u5176\u521d\u59cb\u5316\u4e3a System.in\u3002 \u4f7f\u7528 Scanner.next() \u65b9\u6cd5\u4ece\u63a7\u5236\u53f0\u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26\u3002 \u5c06\u5b57\u7b26\u6dfb\u52a0\u5230\u5b57\u7b26\u4e32\u6570\u7ec4\u4e2d\u3002 \u91cd\u590d\u6b65\u9aa4 2-3\uff0c\u76f4\u5230\u8f93\u5165\u6240\u6709\u6240\u9700\u7684\u5b57\u7b26\u3002 \u793a\u4f8b\u4ee3\u7801\uff1a import java.util.Scanner; public class InputCharactersToArray { public static void main(String[] args) { Scanner input = [&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-39119","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39119","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=39119"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39119\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=39119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=39119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=39119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}