{"id":315,"date":"2019-03-10T22:44:15","date_gmt":"2019-03-10T14:44:15","guid":{"rendered":"https:\/\/103.249.111.182\/?p=315"},"modified":"2024-08-18T00:03:21","modified_gmt":"2024-08-17T16:03:21","slug":"%e7%ac%94%e8%ae%b0javascanner%e7%9a%84%e4%b8%80%e4%b8%aa%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a1%b9","status":"publish","type":"post","link":"https:\/\/7gugu.com\/index.php\/2019\/03\/10\/%e7%ac%94%e8%ae%b0javascanner%e7%9a%84%e4%b8%80%e4%b8%aa%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a1%b9\/","title":{"rendered":"[\u7b14\u8bb0][Java]Scanner\u7684\u4e00\u4e2a\u6ce8\u610f\u4e8b\u9879"},"content":{"rendered":"<h1>\u5e8f:<\/h1>\n<p>\u6700\u8fd1\u5165\u5751Java\u5f00\u53d1,\u5b66\u4e60\u5230\u4f7f\u7528scanner\u83b7\u53d6\u7528\u6237\u8f93\u5165,\u5e76\u4e14\u53d1\u73b0\u4e86\u4e00\u4e9b\u5165\u95e8\u7684\u5751\u70b9,\u5728\u6b64\u5199\u4e00\u70b9\u7b14\u8bb0\u65b9\u4fbf\u4ee5\u540e\u67e5\u627e\u3002<\/p>\n<h1>\u95ee\u9898\u4ee3\u7801:<\/h1>\n<pre>import java.util.*;\n\npublic class Mathmatic {\n\n\tpublic static void main(String[] args) {\n\t\tMathmatic math = new Mathmatic();\n\t\tint result;\n\t\tresult = math.compare();\n\t\tSystem.out.println(result);\n\t\tresult = math.isPrime();\n\t\tSystem.out.println(result);\n\t}\n\t\n\tpublic int compare() {\n\t\tint num1,num2;\n\t\tScanner input = new Scanner(System.in);\n\t\tSystem.out.println(\"\u8bf7\u8f93\u5165\u7b2c\u4e00\u4e2a\u6570\u5b57:\");\n\t\tnum1=input.nextInt();\n\t\tSystem.out.println(\"\u8bf7\u8f93\u5165\u7b2c\u4e8c\u4e2a\u6570\u5b57:\");\n\t\tnum2=input.nextInt();\n                input.close();\n\t\tif(num1==num2) {\n\t\t\treturn 0;\n\t\t}else if(num1&gt;num2) {\n\t\t\treturn 1;\n\t\t}else if(num1&lt;num2) {\n\t\t\treturn -1;\n\t\t}\n\t\treturn 2;\n\t}\n\t\n\tpublic int isPrime() {\n\t\tint prime;\n\t\tScanner input = new Scanner(System.in);\n\t\tSystem.out.println(\"\u8bf7\u8f93\u5165\u4e00\u4e2a\u6570\u5b57:\");\n\t\tprime=input.nextInt();\n\t\tfor(int i=2;i&lt;prime;i++) {\n\t\t\tif(prime%i==0) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\treturn 1;\n\t}\n}\n<\/pre>\n<p>\u6b64\u6bb5\u4ee3\u7801\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d,\u5982\u679c\u8c03\u7528\u4e86compare\u51fd\u6570\u4e4b\u540e,\u518d\u8c03\u7528isPrime\u51fd\u6570,\u5c06\u4f1a\u62a5\u4ee5\u4e0b\u9519\u8bef\u3002<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-317\" src=\"https:\/\/103.249.111.182\/wp-content\/uploads\/2019\/03\/QQ\u622a\u56fe20190310223956.jpg\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" srcset=\"https:\/\/7gugu.com\/wp-content\/uploads\/2019\/03\/QQ\u622a\u56fe20190310223956.jpg 1199w, https:\/\/7gugu.com\/wp-content\/uploads\/2019\/03\/QQ\u622a\u56fe20190310223956-300x74.jpg 300w, https:\/\/7gugu.com\/wp-content\/uploads\/2019\/03\/QQ\u622a\u56fe20190310223956-1024x253.jpg 1024w, https:\/\/7gugu.com\/wp-content\/uploads\/2019\/03\/QQ\u622a\u56fe20190310223956-768x190.jpg 768w\" alt=\"\" width=\"1199\" height=\"296\" \/><\/p>\n<h1>\u9519\u8bef\u5b9a\u4f4d:<\/h1>\n<pre>\t\tnum2=input.nextInt();\n             --&gt;input.close();&lt;--\n<\/pre>\n<p>\u8fd9\u662f\u56e0\u4e3a\u5728\u51fd\u6570\u4e2d\uff0c\u58f0\u660e\u4e86\u4e00\u4e2ascanner\u5bf9\u8c61\uff0c\u5e76\u4e14\u8c03\u7528\u4e86close\u65b9\u6cd5\u3002\u8fd9\u53ef\u80fd\u662f\u7531\u4e8e\u6240\u6709\u7684scanner\u7c7b\u5171\u4eab\u4e00\u4e2a\u8f93\u5165\u6d41\uff0c\u5f53\u5176\u4e2d\u4e00\u4e2a\u8c03\u7528\u5173\u95ed\u51fd\u6570\u7684\u65f6\u5019\uff0c\u6240\u6709\u7684scanner\u5bf9\u8c61\u90fd\u5173\u95ed\u4e86\u3002<\/p>\n<h1>\u89e3\u51b3\u65b9\u6cd5:<\/h1>\n<p><span style=\"color: #ff6600;\"><strong>\u5728\u7a0b\u5e8f\u7684\u6700\u540e,\u518d\u4f7f\u7528close\u65b9\u6cd5<\/strong><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e8f: \u6700\u8fd1\u5165\u5751Java\u5f00\u53d1,\u5b66\u4e60\u5230\u4f7f\u7528scanner\u83b7\u53d6\u7528\u6237\u8f93\u5165,\u5e76\u4e14\u53d1\u73b0\u4e86\u4e00\u4e9b\u5165\u95e8\u7684\u5751\u70b9,\u5728\u6b64\u5199\u4e00\u70b9\u7b14\u8bb0\u65b9\u4fbf &hellip; <a href=\"https:\/\/7gugu.com\/index.php\/2019\/03\/10\/%e7%ac%94%e8%ae%b0javascanner%e7%9a%84%e4%b8%80%e4%b8%aa%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a1%b9\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c[\u7b14\u8bb0][Java]Scanner\u7684\u4e00\u4e2a\u6ce8\u610f\u4e8b\u9879\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,29,13],"tags":[],"class_list":["post-315","post","type-post","status-publish","format-standard","hentry","category-java","category-29","category-13"],"_links":{"self":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/posts\/315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/comments?post=315"}],"version-history":[{"count":1,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/posts\/315\/revisions"}],"predecessor-version":[{"id":3658,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/posts\/315\/revisions\/3658"}],"wp:attachment":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/media?parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/categories?post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/tags?post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}