{"id":1097,"date":"2022-05-17T20:20:32","date_gmt":"2022-05-17T12:20:32","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=1097"},"modified":"2022-05-17T20:20:32","modified_gmt":"2022-05-17T12:20:32","slug":"java%e7%ac%94%e8%af%95%e4%b8%ad%e8%be%93%e5%85%a5%e5%92%8c%e8%be%93%e5%87%ba%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2022\/05\/17\/java%e7%ac%94%e8%af%95%e4%b8%ad%e8%be%93%e5%85%a5%e5%92%8c%e8%be%93%e5%87%ba%e6%80%bb%e7%bb%93\/","title":{"rendered":"Java\u7b14\u8bd5\u4e2d\u8f93\u5165\u548c\u8f93\u51fa\u603b\u7ed3"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u524d\u7f6e\u77e5\u8bc6<\/h2>\n\n\n\n<p><strong>Windows\u4e2d\u7684Enter\u952e\u76f8\u5f53\u4e8e(\\n)+(\\r)<\/strong>\uff01\uff01\u5206\u522b\u5b8c\u6210\u5c06\u5149\u6807\u79fb\u52a8\u5230\u884c\u9996,\u79fb\u52a8\u5230\u4e0b\u4e00\u884c\u7684\u529f\u80fd<br>nextInt():\u76f4\u81f3\u8bfb\u53d6\u5230<strong>\u7a7a\u683c\u6216\u8005\u56de\u8f66<\/strong>\u4e4b\u540e\u7ed3\u675f\u672c\u6b21\u7684<strong>int\u503c<\/strong><br>next():\u76f4\u81f3\u8bfb\u53d6\u5230<strong>\u7a7a\u683c\u4e4b\u540e\u7ed3\u675f\u672c\u6b21<\/strong>String\u503c,<strong>\u4e0d\u53ef\u8bfb\u53d6\u56de\u8f66<\/strong><br>nextLine():\u76f4\u81f3\u8bfb\u53d6\u5230<strong>\u6362\u884c\u7b26\u6216\u56de\u8f66<\/strong>\u4e4b\u540e\u7ed3\u675f\u672c\u6b21\u8bfb\u53d6\u7684String\u503c,<strong>\u53ef\u8bfb\u53d6\u56de\u8f66,\u7a7a\u683c<\/strong><br><strong>\u8f93\u5165\u6570\u636e\u4e3a\u6b63\u6574\u6570\u4e14\u5305\u542b\u591a\u7ec4\u65f6,\u4f7f\u7528\u5faa\u73af\u8f93\u5165,\u7528hasNext()<\/strong><br>\u725b\u5ba2\u7f51\u4e0a\u7684\u8f93\u5165\u548c\u8f93\u51fa\u5927\u6982\u5206\u4e3a\u4ee5\u4e0b\u51e0\u7c7b:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><br>1 \u8bfb\u53d6\u8fde\u7eed\u6574\u6570<\/h2>\n\n\n\n<p><strong>\u8f93\u5165:<\/strong>\u5305\u62ec\u4e24\u4e2a\u6b63\u6574\u6570a,b(1&lt;=a,b&lt;=10^9),\u8f93\u5165\u6570\u636e\u5305\u62ec\u591a\u7ec4.<br><strong>\u8f93\u51fa:<\/strong>a+b\u7684\u7ed3\u679c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\npublic class Main{\n    public static void main(String&#91;] args) {\n        Scanner sc=new Scanner(System.in);\n        while(sc.hasNext()){\n            int a=in.nextInt();\n            int b=in.nextInt();\n            System.out.println(a+b);\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2 \u8bfb\u53d6\u6709\u9650\u6574\u6570<\/strong><\/h2>\n\n\n\n<p><br><strong>\u8f93\u5165:<\/strong>\u7b2c\u4e00\u884c\u5305\u542b\u4e00\u4e2a\u6570\u636e\u7ec4\u6570t(1&lt;=t&lt;=100),\u63a5\u4e0b\u6765\u6bcf\u884c\u5305\u62ec\u4e24\u4e2a\u6b63\u6574\u6570a,b(1&lt;=a,b&lt;=10^9)<br><strong>\u8f93\u51fa:<\/strong>a+b\u7684\u7ed3\u679c.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\npublic class Main{\n    public static void main(String&#91;] args){\n        Scanner in=new Scanner(System.in);\n        int n=in.nextInt();\n        while(n--&gt;0){\n            int a=in.nextInt();\n            int b=in.nextInt();\n            System.out.println(a+b);\n        }\n    }\n}\n\/\/while(n--&gt;0)\u7684\u610f\u601d\u65f6\u5faa\u73afn\u6b21<\/code><\/pre>\n\n\n\n<p><strong>3 \u6bcf\u884c\u8bfb\u53d6\u7a7a\u683c\u9694\u5f00\u7684\u6574\u6570<\/strong><br><strong>\u8f93\u5165:<\/strong>\u8f93\u5165\u6570\u636e\u6709\u591a\u7ec4, \u6bcf\u884c\u8868\u793a\u4e00\u7ec4\u8f93\u5165\u6570\u636e\u3002\u6bcf\u884c\u4e0d\u5b9a\u6709n\u4e2a\u6574\u6570\uff0c\u7a7a\u683c\u9694\u5f00\u3002(1 &lt;= n &lt;= 100).<br><strong>\u8f93\u51fa:<\/strong>\u6bcf\u7ec4\u6570\u636e\u8f93\u51fa\u6c42\u548c\u7684\u7ed3\u679c.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\nimport java.lang.String;\nimport java.lang.Integer;\npublic class Main{\n    public static void main(String&#91;] args){\n        Scanner in=new Scanner(System.in);\n        while(in.hasNext()){\n            String&#91;] temp=in.nextLine().split(\" \");\n            int sum=0;\n            for(String s:temp)\n                sum+=Integer.valueOf(s);\n            System.out.println(sum);\n        }\n    }<\/code><\/pre>\n\n\n\n<p><strong>\u6ce8\u610f:<\/strong><\/p>\n\n\n\n<p>1\u3001\u5f53nextInt()\u6216\u8005next()\u8bfb\u53d6\u5b8c\u6bd5\u5e76\u56de\u8f66\u4e4b\u540e\u5176\u540e\u7d27\u8ddfnextLine()\uff0c\u5c31\u4f1a\u5bfc\u81f4nextLine()<strong>\u8bfb\u53d6\u5230\u7a7a\u503c<\/strong>\uff0c\u56e0\u4e3anextLine()\u81ea\u52a8\u8bfb\u53d6\u5230\u2019\\n\u2019\uff0c\u610f\u5473\u7740\u9047\u5230\u7ed3\u675f\u7b26\u3002\u6b64\u65f6\u6539\u6210\u4f7f\u7528next()\u8ba1\u79d1<br>2\u3001\u6709\u65f6\u5019\u5c06\u5b57\u7b26\u4e32\u8f6c\u4e3a\u6574\u6570\u65f6\uff0c\u4ee3\u7801\u6ca1\u95ee\u9898\u5374\u63d0\u793a\u6570\u7ec4\u8d8a\u754c\uff0c\u5f80\u5f80\u662f\u56e0\u4e3a\u5b57\u7b26\u4e32\u4ee3\u8868\u7684\u6574\u6570\u8d85\u8fc7\u4e86int\u7684\u6700\u503c\uff0c\u9700\u8981\u6539\u7528long\u6765\u4f7f\u7528<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u7f6e\u77e5\u8bc6 Windows\u4e2d\u7684En&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1074,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4],"tags":[],"class_list":["post-1097","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=1097"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1097\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media\/1074"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=1097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=1097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=1097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}