{"id":64124,"date":"2025-05-03T10:57:53","date_gmt":"2025-05-03T02:57:53","guid":{"rendered":"https:\/\/fwq.ai\/blog\/64124\/"},"modified":"2025-05-03T10:57:53","modified_gmt":"2025-05-03T02:57:53","slug":"java%e6%80%8e%e4%b9%88%e7%94%a8%e6%95%b0%e7%bb%84%e8%be%93%e5%85%a5%e5%ad%a6%e7%94%9f%e4%bf%a1%e6%81%af-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/64124\/","title":{"rendered":"java\u600e\u4e48\u7528\u6570\u7ec4\u8f93\u5165\u5b66\u751f\u4fe1\u606f"},"content":{"rendered":"<blockquote><p>\n  \u672c\u6307\u5357\u63d0\u4f9b\u4e86\u4f7f\u7528 java \u6570\u7ec4\u8f93\u5165\u5b66\u751f\u4fe1\u606f\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a\u58f0\u660e\u5b57\u7b26\u4e32\u548c\u6574\u6570\u6570\u7ec4\uff0c\u4ee5\u5b58\u50a8\u5b66\u751f\u59d3\u540d\u548c\u5e74\u9f84\u3002\u786e\u5b9a\u6570\u7ec4\u5927\u5c0f\u5e76\u521b\u5efa\u76f8\u5e94\u957f\u5ea6\u7684\u6570\u7ec4\u3002\u4f7f\u7528 scanner \u5bf9\u8c61\u83b7\u53d6\u7528\u6237\u8f93\u5165\uff0c\u5faa\u73af\u8f93\u5165\u5b66\u751f\u59d3\u540d\u548c\u5e74\u9f84\u3002\u4f7f\u7528\u5faa\u73af\u6253\u5370\u5df2\u8f93\u5165\u7684\u5b66\u751f\u4fe1\u606f\uff0c\u5305\u62ec\u59d3\u540d\u548c\u5e74\u9f84\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/02\/2024110214274797117.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u7528\u6570\u7ec4\u8f93\u5165\u5b66\u751f\u4fe1\u606f\u63d2\u56fe\" alt=\"java\u600e\u4e48\u7528\u6570\u7ec4\u8f93\u5165\u5b66\u751f\u4fe1\u606f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Java \u6570\u7ec4\u8f93\u5165\u5b66\u751f\u4fe1\u606f<\/strong><\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u58f0\u660e\u6570\u7ec4<\/strong><\/p>\n<pre>String[] studentNames; \/\/ \u58f0\u660e\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u7528\u6765\u5b58\u50a8\u5b66\u751f\u59d3\u540d\nint[] studentAges; \/\/ \u58f0\u660e\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u7528\u6765\u5b58\u50a8\u5b66\u751f\u5e74\u9f84<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 2\uff1a\u786e\u5b9a\u6570\u7ec4\u5927\u5c0f<\/strong><\/p>\n<pre>int numOfStudents = 5; \/\/ \u5047\u8bbe\u6709 5 \u4e2a\u5b66\u751f\nstudentNames = new String[numOfStudents]; \/\/ \u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a 5 \u7684\u5b57\u7b26\u4e32\u6570\u7ec4\nstudentAges = new int[numOfStudents]; \/\/ \u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a 5 \u7684\u6574\u6570\u6570\u7ec4<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 3\uff1a\u83b7\u53d6\u7528\u6237\u8f93\u5165<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>Scanner scanner = new Scanner(System.in); \/\/ \u521b\u5efa\u4e00\u4e2a Scanner \u5bf9\u8c61\uff0c\u7528\u4e8e\u83b7\u53d6\u7528\u6237\u8f93\u5165\n\n\/\/ \u5faa\u73af\u8f93\u5165\u5b66\u751f\u59d3\u540d\nfor (int i = 0; i &lt; numOfStudents; i++) {\n    System.out.print(\"\u8bf7\u8f93\u5165\u7b2c \" + (i + 1) + \" \u4e2a\u5b66\u751f\u7684\u59d3\u540d\uff1a\");\n    studentNames[i] = scanner.nextLine();\n}\n\n\/\/ \u5faa\u73af\u8f93\u5165\u5b66\u751f\u5e74\u9f84\nfor (int i = 0; i &lt; numOfStudents; i++) {\n    System.out.print(\"\u8bf7\u8f93\u5165\u7b2c \" + (i + 1) + \" \u4e2a\u5b66\u751f\u7684\u5e74\u9f84\uff1a\");\n    studentAges[i] = scanner.nextInt();\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 4\uff1a\u6253\u5370\u5b66\u751f\u4fe1\u606f<\/strong><\/p>\n<pre>\/\/ \u5faa\u73af\u6253\u5370\u5b66\u751f\u59d3\u540d\nSystem.out.println(\"\u5b66\u751f\u59d3\u540d\uff1a\");\nfor (String studentName : studentNames) {\n    System.out.println(studentName);\n}\n\n\/\/ \u5faa\u73af\u6253\u5370\u5b66\u751f\u5e74\u9f84\nSystem.out.println(\"\u5b66\u751f\u5e74\u9f84\uff1a\");\nfor (int studentAge : studentAges) {\n    System.out.println(studentAge);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u7528\u6570\u7ec4\u8f93\u5165\u5b66\u751f\u4fe1\u606f\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>\u672c\u6307\u5357\u63d0\u4f9b\u4e86\u4f7f\u7528 java \u6570\u7ec4\u8f93\u5165\u5b66\u751f\u4fe1\u606f\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a\u58f0\u660e\u5b57\u7b26\u4e32\u548c\u6574\u6570\u6570\u7ec4\uff0c\u4ee5\u5b58\u50a8\u5b66\u751f\u59d3\u540d\u548c\u5e74\u9f84\u3002\u786e\u5b9a\u6570\u7ec4\u5927\u5c0f\u5e76\u521b\u5efa\u76f8\u5e94\u957f\u5ea6\u7684\u6570\u7ec4\u3002\u4f7f\u7528 scanner \u5bf9\u8c61\u83b7\u53d6\u7528\u6237\u8f93\u5165\uff0c\u5faa\u73af\u8f93\u5165\u5b66\u751f\u59d3\u540d\u548c\u5e74\u9f84\u3002\u4f7f\u7528\u5faa\u73af\u6253\u5370\u5df2\u8f93\u5165\u7684\u5b66\u751f\u4fe1\u606f\uff0c\u5305\u62ec\u59d3\u540d\u548c\u5e74\u9f84\u3002 \u5982\u4f55\u4f7f\u7528 Java \u6570\u7ec4\u8f93\u5165\u5b66\u751f\u4fe1\u606f \u6b65\u9aa4 1\uff1a\u58f0\u660e\u6570\u7ec4 String[] studentNames; \/\/ \u58f0\u660e\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u7528\u6765\u5b58\u50a8\u5b66\u751f\u59d3\u540d int[] studentAges; \/\/ \u58f0\u660e\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u7528\u6765\u5b58\u50a8\u5b66\u751f\u5e74\u9f84 \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 2\uff1a\u786e\u5b9a\u6570\u7ec4\u5927\u5c0f int numOfStudents = 5; \/\/ \u5047\u8bbe\u6709 5 \u4e2a\u5b66\u751f studentNames = new String[numOfStudents]; \/\/ \u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a 5 \u7684\u5b57\u7b26\u4e32\u6570\u7ec4 studentAges = new int[numOfStudents]; \/\/ \u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a 5 \u7684\u6574\u6570\u6570\u7ec4 \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 3\uff1a\u83b7\u53d6\u7528\u6237\u8f93\u5165 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b Scanner scanner = new Scanner(System.in); \/\/ [&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-64124","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64124","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=64124"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64124\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=64124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=64124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=64124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}