{"id":202725,"date":"2025-05-22T08:43:45","date_gmt":"2025-05-22T00:43:45","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202725\/"},"modified":"2025-05-22T08:43:45","modified_gmt":"2025-05-22T00:43:45","slug":"%e6%b7%b1%e5%85%a5%e6%b5%85%e5%87%bajava%e5%87%bd%e6%95%b0%e7%9a%84%e4%bc%98%e5%8a%a3","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202725\/","title":{"rendered":"\u6df1\u5165\u6d45\u51fa:Java\u51fd\u6570\u7684\u4f18\u52a3"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u6df1\u5165\u6d45\u51fa:Java\u51fd\u6570\u7684\u4f18\u52a3<\/h1>\n<p>IT\u884c\u4e1a\u76f8\u5bf9\u4e8e\u4e00\u822c\u4f20\u7edf\u884c\u4e1a\uff0c\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u66f4\u5feb\uff0c\u4e00\u65e6\u505c\u6b62\u4e86\u5b66\u4e60\uff0c\u5f88\u5feb\u5c31\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8e0f\u8e0f\u5b9e\u5b9e\u7684\u4e0d\u65ad\u5b66\u4e60\uff0c\u7cbe\u8fdb\u81ea\u5df1\u7684\u6280\u672f\uff0c\u5c24\u5176\u662f\u521d\u5b66\u8005\u3002\u4eca\u5929\u7ed9\u5927\u5bb6\u6574\u7406\u4e86\u300a\u6df1\u5165\u6d45\u51fa:Java\u51fd\u6570\u7684\u4f18\u52a3\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p>Java \u51fd\u6570\u7684\u4f18\u7f3a\u70b9\uff1a\u4f18\u70b9\uff1a\u4ee3\u7801\u91cd\u7528\u5c01\u88c5\u53ef\u6d4b\u8bd5\u6027\u4ee3\u7801\u53ef\u7ef4\u62a4\u6027\u6027\u80fd\u4f18\u5316\u7f3a\u70b9\uff1a\u6027\u80fd\u5f00\u9500\u8fc7\u5ea6\u5de5\u7a0b\u5316\u547d\u540d\u51b2\u7a81\u8c03\u8bd5\u56f0\u96be<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729936969671cbe49eeb9a.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u6df1\u5165\u6d45\u51fa\uff1aJava \u51fd\u6570\u7684\u4f18\u52a3<\/strong><\/p>\n<p>Java \u51fd\u6570\uff0c\u4e5f\u79f0\u4e3a\u65b9\u6cd5\uff0c\u662f\u4ee3\u7801\u91cd\u7528\u548c\u5c01\u88c5\u7684\u5173\u952e\u90e8\u5206\u3002\u7136\u800c\uff0c\u7406\u89e3\u51fd\u6570\u7684\u4f18\u7f3a\u70b9\u5bf9\u4e8e\u7f16\u5199\u9ad8\u6548\u4e14\u6613\u7ef4\u62a4\u7684\u4ee3\u7801\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p><strong>\u4f18\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u4ee3\u7801\u91cd\u7528\uff1a<\/strong>\u51fd\u6570\u5141\u8bb8\u4f60\u5c06\u4ee3\u7801\u5757\u91cd\u7528\u4e8e\u6574\u4e2a\u9879\u76ee\uff0c\u907f\u514d\u91cd\u590d\u548c\u4fdd\u6301\u4e00\u81f4\u6027\u3002<\/li>\n<li><strong>\u5c01\u88c5\uff1a<\/strong>\u51fd\u6570\u5c06\u76f8\u5173\u4ee3\u7801\u5c01\u88c5\u5728\u547d\u540d\u826f\u597d\u7684\u5355\u5143\u4e2d\uff0c\u63d0\u9ad8\u4e86\u7a0b\u5e8f\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/li>\n<li><strong>\u53ef\u6d4b\u8bd5\u6027\uff1a<\/strong>\u72ec\u7acb\u7684\u51fd\u6570\u53ef\u4ee5\u8f7b\u677e\u5730\u8fdb\u884c\u5355\u5143\u6d4b\u8bd5\uff0c\u786e\u4fdd\u4ee3\u7801\u7684\u6b63\u786e\u6027\u3002<\/li>\n<li><strong>\u4ee3\u7801\u53ef\u7ef4\u62a4\u6027\uff1a<\/strong>\u5f53\u9700\u8981\u4fee\u6539\u529f\u80fd\u65f6\uff0c\u51fd\u6570\u5141\u8bb8\u4f60\u5bf9\u7279\u5b9a\u7684\u4ee3\u7801\u5757\u8fdb\u884c\u66f4\u6539\uff0c\u800c\u4e0d\u662f\u641c\u7d22\u548c\u4fee\u6539\u6574\u4e2a\u4ee3\u7801\u5e93\u3002<\/li>\n<li><strong>\u6027\u80fd\u4f18\u5316\uff1a<\/strong>\u4f7f\u7528\u51fd\u6570\u53ef\u4ee5\u5c06\u5e38\u7528\u64cd\u4f5c\u6253\u5305\u5230\u9ad8\u6548\u7684\u65b9\u6cd5\u4e2d\uff0c\u6700\u5927\u9650\u5ea6\u5730\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p><strong>\u7f3a\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u6027\u80fd\u5f00\u9500\uff1a<\/strong>\u6bcf\u6b21\u8c03\u7528\u51fd\u6570\u90fd\u4f1a\u4ea7\u751f\u4e00\u5b9a\u7a0b\u5ea6\u7684\u6027\u80fd\u5f00\u9500\uff0c\u5305\u62ec\u67e5\u627e\u51fd\u6570\u548c\u5806\u6808\u521b\u5efa\u3002<\/li>\n<li><strong>\u8fc7\u5ea6\u5de5\u7a0b\u5316\uff1a<\/strong>\u5982\u679c\u4e0d\u5408\u7406\u5730\u4f7f\u7528\u51fd\u6570\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8fc7\u5ea6\u5de5\u7a0b\u5316\u548c\u4ee3\u7801\u590d\u6742\u6027\u3002<\/li>\n<li><strong>\u547d\u540d\u51b2\u7a81\uff1a<\/strong>\u5728\u5927\u578b\u9879\u76ee\u4e2d\uff0c\u53ef\u80fd\u51fa\u73b0\u51fd\u6570\u547d\u540d\u51b2\u7a81\uff0c\u5bfc\u81f4\u6df7\u6dc6\u548c\u9519\u8bef\u3002<\/li>\n<li><strong>\u8c03\u8bd5\u56f0\u96be\uff1a<\/strong>\u8ddf\u8e2a\u51fd\u6570\u8c03\u7528\u4e4b\u95f4\u7684\u4ea4\u4e92\u53ef\u80fd\u5177\u6709\u6311\u6218\u6027\uff0c\u7279\u522b\u662f\u5bf9\u4e8e\u9012\u5f52\u51fd\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a<\/strong><\/p>\n<p>\u6211\u4eec\u521b\u5efa\u4e00\u4e2a Java \u7a0b\u5e8f\u6765\u8ba1\u7b97\u4e24\u4e2a\u6570\u5b57\u7684\u6700\u5c0f\u516c\u500d\u6570 (LCM)\uff1a<\/p>\n<pre>import java.util.Scanner;\n\npublic class LCM {\n\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n\n        \/\/ \u8f93\u5165\u4e24\u4e2a\u6570\u5b57\n        System.out.println(\"\u8f93\u5165\u7b2c\u4e00\u4e2a\u6570\u5b57\uff1a\");\n        int num1 = scanner.nextInt();\n        System.out.println(\"\u8f93\u5165\u7b2c\u4e8c\u4e2a\u6570\u5b57\uff1a\");\n        int num2 = scanner.nextInt();\n\n        \/\/ \u8ba1\u7b97\u6700\u5c0f\u516c\u500d\u6570\n        int lcm = findLCM(num1, num2);\n\n        \/\/ \u8f93\u51fa\u7ed3\u679c\n        System.out.println(\"\u6700\u5c0f\u516c\u500d\u6570\u4e3a\uff1a\" + lcm);\n    }\n\n    public static int findLCM(int num1, int num2) {\n        \/\/ \u627e\u5230\u8f83\u5927\u6570\u548c\u8f83\u5c0f\u6570\n        int greater = Math.max(num1, num2);\n        int smaller = Math.min(num1, num2);\n\n        \/\/ \u9010\u4e00\u9012\u589e\u8f83\u5927\u6570\uff0c\u76f4\u5230\u627e\u5230\u7b2c\u4e00\u4e2a\u540c\u65f6\u80fd\u88ab\u8f83\u5927\u6570\u548c\u8f83\u5c0f\u6570\u6574\u9664\u7684\u6570\n        int lcm = greater;\n        while (true) {\n            if (lcm % smaller == 0) {\n                break;\n            }\n            lcm++;\n        }\n\n        return lcm;\n    }\n}<\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>findLCM()<\/code> \u51fd\u6570\u5c01\u88c5\u4e86\u8ba1\u7b97 LCM \u7684\u903b\u8f91\uff0c\u4f7f\u4e3b\u65b9\u6cd5\u66f4\u52a0\u7b80\u6d01\u6613\u8bfb\u3002\u7136\u800c\uff0c<code>findLCM()<\/code> \u672c\u8eab\u662f\u4e00\u4e2a\u6bd4\u8f83\u590d\u6742\u7684\u51fd\u6570\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8c03\u8bd5\u4e0a\u7684\u56f0\u96be\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u6df1\u5165\u6d45\u51fa:Java\u51fd\u6570\u7684\u4f18\u52a3\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8ejava,\u51fd\u6570\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5165\u6d45\u51fa:Java\u51fd\u6570\u7684\u4f18\u52a3 I&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-202725","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202725","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=202725"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202725\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}