{"id":65213,"date":"2025-05-03T13:25:22","date_gmt":"2025-05-03T05:25:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65213\/"},"modified":"2025-05-03T13:25:22","modified_gmt":"2025-05-03T05:25:22","slug":"java%e4%b8%ad%e6%80%8e%e4%b9%88%e8%be%93%e5%85%a5%e6%95%b0%e7%bb%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65213\/","title":{"rendered":"java\u4e2d\u600e\u4e48\u8f93\u5165\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u8f93\u5165\u6570\u7ec4\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u76f4\u63a5\u8d4b\u503c\u548c\u4f7f\u7528 scanner \u7c7b\u3002\u76f4\u63a5\u8d4b\u503c\u662f\u5728\u58f0\u660e\u6570\u7ec4\u65f6\u6307\u5b9a\u5143\u7d20\u503c\uff0c\u5982\uff1aint[] numbers = {1, 2, 3, 4, 5}\u3002\u4f7f\u7528 scanner \u7c7b\u5219\u9700\u8981\u521b\u5efa scanner \u5bf9\u8c61\uff0c\u5e76\u4f7f\u7528 nextint()\u3001nextdouble() \u6216 nextline() \u7b49\u65b9\u6cd5\u4ece\u8f93\u5165\u6e90\uff08\u5982\u63a7\u5236\u53f0\uff09\u83b7\u53d6\u8f93\u5165\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/12\/2024111212094611610.jpg\" class=\"aligncenter\" title=\"java\u4e2d\u600e\u4e48\u8f93\u5165\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u4e2d\u600e\u4e48\u8f93\u5165\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u8f93\u5165\u6570\u7ec4\u7684\u4e24\u79cd\u65b9\u6cd5<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4e24\u79cd\u65b9\u6cd5\u8f93\u5165\u6570\u7ec4\uff1a<\/p>\n<p><strong>1. \u76f4\u63a5\u8d4b\u503c<\/strong><\/p>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u662f\u5728\u58f0\u660e\u6570\u7ec4\u65f6\u76f4\u63a5\u6307\u5b9a\u5143\u7d20\u503c\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[] numbers = {1, 2, 3, 4, 5};\nString[] names = {\"John\", \"Mary\", \"Bob\"};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 Scanner \u7c7b<\/strong><\/p>\n<p>Scanner \u7c7b\u63d0\u4f9b\u4e86\u7528\u4e8e\u8f93\u5165\u7684 nextInt()\u3001nextDouble() \u548c nextLine() \u7b49\u65b9\u6cd5\u3002\u8981\u4f7f\u7528\u6b64\u65b9\u6cd5\uff0c\u60a8\u9700\u8981\u521b\u5efa Scanner \u5bf9\u8c61\u5e76\u5c06\u5176\u8fde\u63a5\u5230\u8f93\u5165\u6e90\uff08\u4f8b\u5982\u63a7\u5236\u53f0\uff09\uff1a<\/p>\n<pre>import java.util.Scanner;\n\nScanner scanner = new Scanner(System.in);\n\n\/\/ \u8f93\u5165\u6574\u578b\u6570\u7ec4\nSystem.out.println(\"\u8f93\u5165\u6574\u578b\u6570\u7ec4\uff0c\u4ee5\u7a7a\u683c\u5206\u9694\uff1a\");\nString input = scanner.nextLine();\nString[] tokens = input.split(\" \");\nint[] numbers = new int[tokens.length];\nfor (int i = 0; i &lt; tokens.length; i++) {\n    numbers[i] = Integer.parseInt(tokens[i]);\n}\n\n\/\/ \u8f93\u5165\u5b57\u7b26\u4e32\u6570\u7ec4\nSystem.out.println(\"\u8f93\u5165\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u4ee5\u7a7a\u683c\u5206\u9694\uff1a\");\ninput = scanner.nextLine();\nString[] tokens = input.split(\" \");\nString[] names = new String[tokens.length];\nfor (int i = 0; i &lt; tokens.length; i++) {\n    names[i] = tokens[i];\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u4e2d\u600e\u4e48\u8f93\u5165\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>java \u4e2d\u8f93\u5165\u6570\u7ec4\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u76f4\u63a5\u8d4b\u503c\u548c\u4f7f\u7528 scanner \u7c7b\u3002\u76f4\u63a5\u8d4b\u503c\u662f\u5728\u58f0\u660e\u6570\u7ec4\u65f6\u6307\u5b9a\u5143\u7d20\u503c\uff0c\u5982\uff1aint[] numbers = {1, 2, 3, 4, 5}\u3002\u4f7f\u7528 scanner \u7c7b\u5219\u9700\u8981\u521b\u5efa scanner \u5bf9\u8c61\uff0c\u5e76\u4f7f\u7528 nextint()\u3001nextdouble() \u6216 nextline() \u7b49\u65b9\u6cd5\u4ece\u8f93\u5165\u6e90\uff08\u5982\u63a7\u5236\u53f0\uff09\u83b7\u53d6\u8f93\u5165\u3002 Java \u4e2d\u8f93\u5165\u6570\u7ec4\u7684\u4e24\u79cd\u65b9\u6cd5 \u5728 Java \u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4e24\u79cd\u65b9\u6cd5\u8f93\u5165\u6570\u7ec4\uff1a 1. \u76f4\u63a5\u8d4b\u503c \u8fd9\u79cd\u65b9\u6cd5\u662f\u5728\u58f0\u660e\u6570\u7ec4\u65f6\u76f4\u63a5\u6307\u5b9a\u5143\u7d20\u503c\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b int[] numbers = {1, 2, 3, 4, 5}; String[] names = {&#8220;John&#8221;, &#8220;Mary&#8221;, &#8220;Bob&#8221;}; \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 Scanner \u7c7b Scanner \u7c7b\u63d0\u4f9b\u4e86\u7528\u4e8e\u8f93\u5165\u7684 nextInt()\u3001nextDouble() \u548c nextLine() \u7b49\u65b9\u6cd5\u3002\u8981\u4f7f\u7528\u6b64\u65b9\u6cd5\uff0c\u60a8\u9700\u8981\u521b\u5efa Scanner \u5bf9\u8c61\u5e76\u5c06\u5176\u8fde\u63a5\u5230\u8f93\u5165\u6e90\uff08\u4f8b\u5982\u63a7\u5236\u53f0\uff09\uff1a [&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-65213","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65213","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=65213"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65213\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}