{"id":34517,"date":"2024-11-26T15:19:43","date_gmt":"2024-11-26T07:19:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/34517\/"},"modified":"2024-11-26T15:19:43","modified_gmt":"2024-11-26T07:19:43","slug":"java%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0%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\/34517\/","title":{"rendered":"java\u600e\u4e48\u5b9e\u73b0\u8f93\u5165\u5b57\u7b26\u4e32\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u8f93\u5165\u5b57\u7b26\u4e32\u6570\u7ec4\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528 scanner \u7c7b\u9010\u4e2a\u8f93\u5165\u5b57\u7b26\u4e32\uff0c\u6216\u8005\u4f7f\u7528 arrays.aslist() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u4ee5\u7a7a\u683c\u5206\u9694\u540e\u8f6c\u6362\u4e3a\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/02\/2024110215362067888.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u5b9e\u73b0\u8f93\u5165\u5b57\u7b26\u4e32\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u5b9e\u73b0\u8f93\u5165\u5b57\u7b26\u4e32\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u7528 Java \u5b9e\u73b0\u8f93\u5165<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\u53ef\u4ee5\u8f93\u5165\u5b57\u7b26\u4e32\u6570\u7ec4\uff1a<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528 Scanner \u7c7b<\/strong><\/p>\n<pre>import java.util.Scanner;\n\npublic class InputStringArray {\n\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n\n        \/\/ \u83b7\u53d6\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u6570\u7ec4\u957f\u5ea6\n        System.out.println(\"\u8bf7\u8f93\u5165\u6570\u7ec4\u957f\u5ea6\uff1a\");\n        int length = scanner.nextInt();\n\n        \/\/ \u521b\u5efa\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u6765\u5b58\u50a8\u8f93\u5165\u7684\u5b57\u7b26\u4e32\n        String[] array = new String[length];\n\n        \/\/ \u9010\u4e2a\u8f93\u5165\u5b57\u7b26\u4e32\n        for (int i = 0; i &lt; length; i++) {\n            System.out.println(\"\u8bf7\u8f93\u5165\u7b2c\" + (i + 1) + \"\u4e2a\u5b57\u7b26\u4e32\uff1a\");\n            array[i] = scanner.nextLine();\n        }\n\n        \/\/ \u6253\u5370\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u6570\u7ec4\n        System.out.println(\"\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u6570\u7ec4\u4e3a\uff1a\");\n        for (String str : array) {\n            System.out.println(str);\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528 Arrays.asList() \u65b9\u6cd5<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>import java.util.Arrays;\n\npublic class InputStringArray {\n\n    public static void main(String[] args) {\n        \/\/ \u83b7\u53d6\u8f93\u5165\u7684\u5b57\u7b26\u4e32\uff08\u4ee5\u7a7a\u683c\u5206\u9694\uff09\n        System.out.println(\"\u8bf7\u8f93\u5165\u5b57\u7b26\u4e32\uff08\u4ee5\u7a7a\u683c\u5206\u9694\uff09\uff1a\");\n        String input = input.nextLine();\n\n        \/\/ \u4f7f\u7528 Arrays.asList() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u7ec4\n        String[] array = input.split(\" \");\n\n        \/\/ \u6253\u5370\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u6570\u7ec4\n        System.out.println(\"\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u6570\u7ec4\u4e3a\uff1a\");\n        for (String str : array) {\n            System.out.println(str);\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u5b9e\u73b0\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>java \u4e2d\u8f93\u5165\u5b57\u7b26\u4e32\u6570\u7ec4\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528 scanner \u7c7b\u9010\u4e2a\u8f93\u5165\u5b57\u7b26\u4e32\uff0c\u6216\u8005\u4f7f\u7528 arrays.aslist() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u4ee5\u7a7a\u683c\u5206\u9694\u540e\u8f6c\u6362\u4e3a\u6570\u7ec4\u3002 \u5982\u4f55\u7528 Java \u5b9e\u73b0\u8f93\u5165 \u5728 Java \u4e2d\uff0c\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\u53ef\u4ee5\u8f93\u5165\u5b57\u7b26\u4e32\u6570\u7ec4\uff1a \u65b9\u6cd5 1\uff1a\u4f7f\u7528 Scanner \u7c7b import java.util.Scanner; public class InputStringArray { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); \/\/ \u83b7\u53d6\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u6570\u7ec4\u957f\u5ea6 System.out.println(&#8220;\u8bf7\u8f93\u5165\u6570\u7ec4\u957f\u5ea6\uff1a&#8221;); int length = scanner.nextInt(); \/\/ \u521b\u5efa\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u6765\u5b58\u50a8\u8f93\u5165\u7684\u5b57\u7b26\u4e32 String[] array = new String[length]; \/\/ \u9010\u4e2a\u8f93\u5165\u5b57\u7b26\u4e32 for (int i = 0; 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-34517","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34517","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=34517"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34517\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=34517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=34517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=34517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}