{"id":34617,"date":"2024-11-26T13:49:56","date_gmt":"2024-11-26T05:49:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/34617\/"},"modified":"2024-11-26T13:49:56","modified_gmt":"2024-11-26T05:49:56","slug":"java%e6%80%8e%e4%b9%88%e8%87%aa%e5%b7%b1%e8%be%93%e5%85%a5%e4%b8%80%e4%b8%b2%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/34617\/","title":{"rendered":"java\u600e\u4e48\u81ea\u5df1\u8f93\u5165\u4e00\u4e32\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u6709\u4e24\u79cd\u65b9\u6cd5\u53ef\u7528\u4e8e\u81ea\u5b9a\u4e49\u8f93\u5165\u4e00\u4e32\u6570\u7ec4\uff1a\u4f7f\u7528 scanner \u83b7\u53d6\u8f93\u5165\u5e76\u5b58\u50a8\u5728 int[] \u4e2d\u3002\u4f7f\u7528 bufferedreader \u8bfb\u53d6\u8f93\u5165\u5e76\u5c06\u5176\u89e3\u6790\u4e3a int[]\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/02\/2024110218003576806.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u81ea\u5df1\u8f93\u5165\u4e00\u4e32\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u81ea\u5df1\u8f93\u5165\u4e00\u4e32\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u7528 Java \u81ea\u5b9a\u4e49\u8f93\u5165\u4e00\u4e32\u6570\u7ec4<\/strong><\/p>\n<p>\u8981\u81ea\u5b9a\u4e49\u8f93\u5165\u4e00\u4e32\u6570\u7ec4\uff0cJava \u63d0\u4f9b\u4e86\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528 Scanner<\/strong><\/p>\n<pre>import java.util.Scanner;\n\npublic class ArrayInput {\n    public static void main(String[] args) {\n        Scanner input = new Scanner(System.in);\n\n        \/\/ \u58f0\u660e\u4e00\u4e2a\u6570\u7ec4\u6765\u5b58\u50a8\u8f93\u5165\u503c\n        int[] numbers = new int[5];\n\n        \/\/ \u4f7f\u7528\u5faa\u73af\u4ece\u7528\u6237\u83b7\u53d6\u8f93\u5165\n        for (int i = 0; i &lt; numbers.length; i++) {\n            System.out.print(\"\u8f93\u5165\u7b2c \" + (i + 1) + \" \u4e2a\u6570\uff1a\");\n            numbers[i] = input.nextInt();\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528 BufferedReader<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class ArrayInput {\n    public static void main(String[] args) {\n        try {\n            \/\/ \u521b\u5efa\u4e00\u4e2a\u8bfb\u53d6\u5668\u4ee5\u4ece\u63a7\u5236\u53f0\u83b7\u53d6\u8f93\u5165\n            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\n            \/\/ \u58f0\u660e\u4e00\u4e2a\u6570\u7ec4\u6765\u5b58\u50a8\u8f93\u5165\u503c\n            int[] numbers = new int[5];\n\n            \/\/ \u4f7f\u7528\u5faa\u73af\u4ece\u7528\u6237\u83b7\u53d6\u8f93\u5165\n            for (int i = 0; i &lt; numbers.length; i++) {\n                System.out.print(\"\u8f93\u5165\u7b2c \" + (i + 1) + \" \u4e2a\u6570\uff1a\");\n                String input = reader.readLine();\n                numbers[i] = Integer.parseInt(input);\n            }\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u80fd\u8ba9\u4f60\u4ece\u7528\u6237\u90a3\u91cc\u83b7\u53d6\u4e00\u4e32\u6570\u7ec4\u8f93\u5165\u3002\u7b2c\u4e00\u4e2a\u65b9\u6cd5\uff08\u4f7f\u7528 Scanner\uff09\u76f8\u5bf9\u7b80\u5355\uff0c\u800c\u7b2c\u4e8c\u4e2a\u65b9\u6cd5\uff08\u4f7f\u7528 BufferedReader\uff09\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u7075\u6d3b\u6027\uff0c\u56e0\u4e3a\u4f60\u53ef\u4ee5\u4f7f\u7528 readLine() \u8bfb\u53d6\u4efb\u4f55\u7c7b\u578b\u7684\u8f93\u5165\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u81ea\u5df1\u8f93\u5165\u4e00\u4e32\u6570\u7ec4\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>\u6709\u4e24\u79cd\u65b9\u6cd5\u53ef\u7528\u4e8e\u81ea\u5b9a\u4e49\u8f93\u5165\u4e00\u4e32\u6570\u7ec4\uff1a\u4f7f\u7528 scanner \u83b7\u53d6\u8f93\u5165\u5e76\u5b58\u50a8\u5728 int[] \u4e2d\u3002\u4f7f\u7528 bufferedreader \u8bfb\u53d6\u8f93\u5165\u5e76\u5c06\u5176\u89e3\u6790\u4e3a int[]\u3002 \u7528 Java \u81ea\u5b9a\u4e49\u8f93\u5165\u4e00\u4e32\u6570\u7ec4 \u8981\u81ea\u5b9a\u4e49\u8f93\u5165\u4e00\u4e32\u6570\u7ec4\uff0cJava \u63d0\u4f9b\u4e86\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a \u65b9\u6cd5 1\uff1a\u4f7f\u7528 Scanner import java.util.Scanner; public class ArrayInput { public static void main(String[] args) { Scanner input = new Scanner(System.in); \/\/ \u58f0\u660e\u4e00\u4e2a\u6570\u7ec4\u6765\u5b58\u50a8\u8f93\u5165\u503c int[] numbers = new int[5]; \/\/ \u4f7f\u7528\u5faa\u73af\u4ece\u7528\u6237\u83b7\u53d6\u8f93\u5165 for (int i = 0; i &lt; numbers.length; i++) { System.out.print(&#8220;\u8f93\u5165\u7b2c &#8221; + [&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-34617","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34617","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=34617"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34617\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=34617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=34617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=34617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}