{"id":66823,"date":"2025-05-03T15:06:58","date_gmt":"2025-05-03T07:06:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66823\/"},"modified":"2025-05-03T15:06:58","modified_gmt":"2025-05-03T07:06:58","slug":"java%e8%be%93%e5%85%a5%e4%b8%80%e4%b8%aa%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e6%8e%a5%e5%8f%97-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66823\/","title":{"rendered":"JAVA\u8f93\u5165\u4e00\u4e2a\u6570\u7ec4\u600e\u4e48\u63a5\u53d7"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u63a5\u6536\u6570\u7ec4\u8f93\u5165\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a\u4f7f\u7528 scanner \u7c7b\uff1a\u901a\u8fc7 scanner \u5bf9\u8c61\u8bfb\u53d6\u6570\u7ec4\u957f\u5ea6\uff0c\u521b\u5efa\u6570\u7ec4\uff0c\u5e76\u4f7f\u7528\u5faa\u73af\u8bfb\u53d6\u5143\u7d20\u3002\u4f7f\u7528 bufferedreader \u7c7b\uff1a\u8bfb\u53d6\u8f93\u5165\u884c\uff0c\u62c6\u5206\u5143\u7d20\uff0c\u5e76\u8f6c\u6362\u4e3a\u6574\u578b\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/17\/2024111711241788313.jpg\" class=\"aligncenter\" title=\"JAVA\u8f93\u5165\u4e00\u4e2a\u6570\u7ec4\u600e\u4e48\u63a5\u53d7\u63d2\u56fe\" alt=\"JAVA\u8f93\u5165\u4e00\u4e2a\u6570\u7ec4\u600e\u4e48\u63a5\u53d7\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Java \u4e2d\u63a5\u6536\u6570\u7ec4\u8f93\u5165<\/strong><\/p>\n<p>\u5728 Java \u4e2d\u63a5\u6536\u6570\u7ec4\u8f93\u5165\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528 Scanner \u7c7b<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u6b65\u9aa4 1\uff1a<\/strong> \u521b\u5efa\u4e00\u4e2a Scanner \u5bf9\u8c61\uff0c\u5e76\u4f7f\u7528 System.in \u4f5c\u4e3a\u8f93\u5165\u6d41\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>Scanner scanner = new Scanner(System.in);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u6b65\u9aa4 2\uff1a<\/strong> \u8bfb\u53d6\u6570\u7ec4\u7684\u957f\u5ea6\uff1a<\/p>\n<pre>int length = scanner.nextInt();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u6b65\u9aa4 3\uff1a<\/strong> \u521b\u5efa\u4e00\u4e2a\u5177\u6709\u6307\u5b9a\u957f\u5ea6\u7684\u6570\u7ec4\uff1a<\/p>\n<pre>int[] array = new int[length];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u6b65\u9aa4 4\uff1a<\/strong> \u4f7f\u7528\u5faa\u73af\u8bfb\u53d6\u6570\u7ec4\u5143\u7d20\uff1a<\/p>\n<pre>for (int i = 0; i &lt; length; i++) {\n  array[i] = scanner.nextInt();\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528 BufferedReader \u7c7b<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u6b65\u9aa4 1\uff1a<\/strong> \u521b\u5efa\u4e00\u4e2a BufferedReader\u5bf9\u8c61\uff0c\u5e76\u4f7f\u7528System.in\u4f5c\u4e3a\u8f93\u5165\u6d41\uff1a<\/p>\n<pre>BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u6b65\u9aa4 2\uff1a<\/strong> \u8bfb\u53d6\u8f93\u5165\u884c\uff1a<\/p>\n<pre>String line = reader.readLine();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u6b65\u9aa4 3\uff1a<\/strong> \u5c06\u8f93\u5165\u884c\u62c6\u5206\u4e3a\u5143\u7d20\uff0c\u5e76\u8f6c\u6362\u4e3a\u6574\u578b\u6570\u7ec4\uff1a<\/p>\n<pre>String[] elements = line.split(\" \");\nint[] array = new int[elements.length];\nfor (int i = 0; i &lt; elements.length; i++) {\n  array[i] = Integer.parseInt(elements[i]);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fJAVA\u8f93\u5165\u4e00\u4e2a\u6570\u7ec4\u600e\u4e48\u63a5\u53d7\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\u63a5\u6536\u6570\u7ec4\u8f93\u5165\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a\u4f7f\u7528 scanner \u7c7b\uff1a\u901a\u8fc7 scanner \u5bf9\u8c61\u8bfb\u53d6\u6570\u7ec4\u957f\u5ea6\uff0c\u521b\u5efa\u6570\u7ec4\uff0c\u5e76\u4f7f\u7528\u5faa\u73af\u8bfb\u53d6\u5143\u7d20\u3002\u4f7f\u7528 bufferedreader \u7c7b\uff1a\u8bfb\u53d6\u8f93\u5165\u884c\uff0c\u62c6\u5206\u5143\u7d20\uff0c\u5e76\u8f6c\u6362\u4e3a\u6574\u578b\u6570\u7ec4\u3002 \u5982\u4f55\u5728 Java \u4e2d\u63a5\u6536\u6570\u7ec4\u8f93\u5165 \u5728 Java \u4e2d\u63a5\u6536\u6570\u7ec4\u8f93\u5165\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a \u65b9\u6cd5 1\uff1a\u4f7f\u7528 Scanner \u7c7b \u6b65\u9aa4 1\uff1a \u521b\u5efa\u4e00\u4e2a Scanner \u5bf9\u8c61\uff0c\u5e76\u4f7f\u7528 System.in \u4f5c\u4e3a\u8f93\u5165\u6d41\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b Scanner scanner = new Scanner(System.in); \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 2\uff1a \u8bfb\u53d6\u6570\u7ec4\u7684\u957f\u5ea6\uff1a int length = scanner.nextInt(); \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 3\uff1a \u521b\u5efa\u4e00\u4e2a\u5177\u6709\u6307\u5b9a\u957f\u5ea6\u7684\u6570\u7ec4\uff1a int[] array = new int[length]; \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 4\uff1a \u4f7f\u7528\u5faa\u73af\u8bfb\u53d6\u6570\u7ec4\u5143\u7d20\uff1a for (int 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-66823","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66823","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=66823"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66823\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}