{"id":1188,"date":"2015-02-28T01:28:00","date_gmt":"2015-02-27T17:28:00","guid":{"rendered":"https:\/\/www.ray650128.com\/wordpress\/?p=1188"},"modified":"2021-10-03T02:33:03","modified_gmt":"2021-10-02T18:33:03","slug":"java%e6%b1%82%e6%9c%80%e5%a4%a7%e5%85%ac%e5%9b%a0%e6%95%b8%e3%80%81%e6%9c%80%e5%b0%8f%e5%85%ac%e5%80%8d%e6%95%b8%e3%80%81%e4%b9%9d%e4%b9%9d%e4%b9%98%e6%b3%95%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/blog.ray650128.com\/?p=1188","title":{"rendered":"JAVA\u6c42\u6700\u5927\u516c\u56e0\u6578\u3001\u6700\u5c0f\u516c\u500d\u6578\u3001\u4e5d\u4e5d\u4e58\u6cd5\u8868"},"content":{"rendered":"\n<p>\u6700\u8fd1\u5728\u56de\u9867\u4e00\u4e9b\u7c21\u55ae\u7684\u7a0b\u5f0f\u904b\u7528\uff0c\u611f\u89ba\u592a\u4e45\u6c92\u7528\u90fd\u5feb\u9084\u7d66\u8001\u5e2b\u4e86&#8230;.<\/p>\n\n\n\n<p>\u56e0\u6b64\u4f86\u8907\u7fd2\u4e00\u4e9b\u4ee5\u524d\u4e0a\u8ab2\u6642\u8001\u5e2b\u6700\u559c\u6b61\u6559\u7684\u6771\u897f\uff1a\u6700\u5927\u516c\u56e0\u6578\u3001\u6700\u5c0f\u516c\u500d\u6578\u3001\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6700\u5927\u516c\u56e0\u6578\u53ca\u6700\u5c0f\u516c\u500d\u6578<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u8ff4\u5708\u5beb\u6cd5<\/h3>\n\n\n\n<p>\u9996\u5148\u662ffor\u8ff4\u5708\u89e3\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"java\" class=\"language-java line-numbers\">public class MyClass {\n    public static void main(String args[]) {\n        int x = 84;  \/\/ \u6578\u503c1\n        int y = 70;  \/\/ \u6578\u503c2\n              \n        int temp = 1;  \/\/ \u66ab\u5b58\u7528\u8b8a\u6578\n        \n        \/\/ \u4f7f\u7528 for \u8ff4\u5708\n        for (int i = 2; i &lt;= x; i++) {\n            \/\/ \u5224\u65b7\u5169\u6578\u662f\u5426\u90fd\u88ab\u6574\u9664\n            if (x % i == 0 &amp;&amp; y % i == 0) {\n                temp = i;\n            }\n        }\n        \n        System.out.println(\"\u6700\u5927\u516c\u56e0\u6578:\" + temp);\n        System.out.println(\"\u6700\u5c0f\u516c\u500d\u6578:\" + x * y \/ temp);\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u57f7\u884c\u7d50\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">\u6700\u5927\u516c\u56e0\u6578:14\n\u6700\u5c0f\u516c\u500d\u6578:420<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>while\u89e3\u6cd5 \u5982\u4e0b\uff1a <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"java\" class=\"language-java line-numbers\">public class MyClass {\n    public static void main(String args[]) {\n        int x = 84;\n        int y = 70;\n        \n        int in1 = x;\n        int in2 = y;\n          \n        int temp = 1;\n          \n        while (in1 % in2 != 0) {\n            temp = in2;\n            in2 = in1 % in2;\n            in1 = temp;\n        }\n          \n        System.out.println(\"\u6700\u5927\u516c\u56e0\u6578:\" + in2);\n        System.out.println(\"\u6700\u5c0f\u516c\u500d\u6578:\" + x * y \/ in2);\n    }\n}<\/code><\/pre>\n\n\n\n<p> \u57f7\u884c\u7d50\u679c\u5982\u4e0b\uff1a <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">\u6700\u5927\u516c\u56e0\u6578:14\n\u6700\u5c0f\u516c\u500d\u6578:420<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>do-while\u89e3\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"java\" class=\"language-java\">public class MyClass {\n    public static void main(String args[]) {\n        int x = 84;\n        int y = 70;\n        \n        int in1 = x;\n        int in2 = y;\n          \n        int temp = 1;\n          \n        do {\n            temp = in2;\n            in2 = in1 % in2;\n            in1 = temp;\n        } while (in1 % in2 != 0);\n          \n        System.out.println(\"\u6700\u5927\u516c\u56e0\u6578:\" + in2);\n        System.out.println(\"\u6700\u5c0f\u516c\u500d\u6578:\" + x * y \/ in2);\n    }\n}<\/code><\/pre>\n\n\n\n<p>  \u57f7\u884c\u7d50\u679c\u5982\u4e0b\uff1a  <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">\u6700\u5927\u516c\u56e0\u6578:14\n\u6700\u5c0f\u516c\u500d\u6578:420<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u905e\u8ff4\u5beb\u6cd5<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"java\" class=\"language-java line-numbers\">public class MyClass {\n    public static void main(String args[]) {\n        int x = 84;\n        int y = 70;\n        \n        System.out.println(\"\u6700\u5927\u516c\u56e0\u6578:\" + gcd(x, y));\n        System.out.println(\"\u6700\u5c0f\u516c\u500d\u6578:\" + x * y \/ gcd(x, y));\n    }\n    \n    private static int gcd(int a, int b) { \n        if(b == 0) \n            return a; \n        else \n            return gcd(b, a % b); \n    }\n}<\/code><\/pre>\n\n\n\n<p> \u57f7\u884c\u7d50\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">\u6700\u5927\u516c\u56e0\u6578:14\n\u6700\u5c0f\u516c\u500d\u6578:420<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u9010\u884c\u6392\u5217<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"java\" class=\"language-java line-numbers\">public class MyClass {\n    public static void main(String args[]) {\n        for (int i = 1; i &lt;= 9; i++) {\n            for (int j = 1; j &lt;= i; j++) {\n                System.out.print(i + \"x\" + j + \"=\" + i*j + \"\\t\");\n            }\n            System.out.println();\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u7d50\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">1x1=1\t\n2x1=2\t2x2=4\t\n3x1=3\t3x2=6\t3x3=9\t\n4x1=4\t4x2=8\t4x3=12\t4x4=16\t\n5x1=5\t5x2=10\t5x3=15\t5x4=20\t5x5=25\t\n6x1=6\t6x2=12\t6x3=18\t6x4=24\t6x5=30\t6x6=36\t\n7x1=7\t7x2=14\t7x3=21\t7x4=28\t7x5=35\t7x6=42\t7x7=49\t\n8x1=8\t8x2=16\t8x3=24\t8x4=32\t8x5=40\t8x6=48\t8x7=56\t8x8=64\t\n9x1=9\t9x2=18\t9x3=27\t9x4=36\t9x5=45\t9x6=54\t9x7=63\t9x8=72\t9x9=81<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u9010\u5217\u6392\u5217<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"java\" class=\"language-java\">public class MyClass {\n    public static void main(String args[]) {\n        for (int i = 1; i &lt;= 9; i++) {\n            for (int j = 1; j &lt;= i; j++) {\n                System.out.print(j + \"x\" + i + \"=\" + i*j + \"\\t\");\n            }\n            System.out.println();\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p> \u7d50\u679c\u5982\u4e0b\uff1a <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">1x1=1\t\n1x2=2\t2x2=4\t\n1x3=3\t2x3=6\t3x3=9\t\n1x4=4\t2x4=8\t3x4=12\t4x4=16\t\n1x5=5\t2x5=10\t3x5=15\t4x5=20\t5x5=25\t\n1x6=6\t2x6=12\t3x6=18\t4x6=24\t5x6=30\t6x6=36\t\n1x7=7\t2x7=14\t3x7=21\t4x7=28\t5x7=35\t6x7=42\t7x7=49\t\n1x8=8\t2x8=16\t3x8=24\t4x8=32\t5x8=40\t6x8=48\t7x8=56\t8x8=64\t\n1x9=9\t2x9=18\t3x9=27\t4x9=36\t5x9=45\t6x9=54\t7x9=63\t8x9=72\t9x9=81<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5728\u56de\u9867\u4e00\u4e9b\u7c21\u55ae\u7684\u7a0b\u5f0f\u904b\u7528\uff0c\u611f\u89ba\u592a\u4e45\u6c92\u7528\u90fd\u5feb\u9084\u7d66\u8001\u5e2b\u4e86&#8230;. \u56e0\u6b64\u4f86\u8907\u7fd2\u4e00\u4e9b\u4ee5\u524d\u4e0a\u8ab2\u6642\u8001\u5e2b\u6700\u559c\u6b61\u6559 &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-1188","post","type-post","status-publish","format-standard","hentry","category-2"],"_links":{"self":[{"href":"https:\/\/blog.ray650128.com\/index.php?rest_route=\/wp\/v2\/posts\/1188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ray650128.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ray650128.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ray650128.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ray650128.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1188"}],"version-history":[{"count":5,"href":"https:\/\/blog.ray650128.com\/index.php?rest_route=\/wp\/v2\/posts\/1188\/revisions"}],"predecessor-version":[{"id":1193,"href":"https:\/\/blog.ray650128.com\/index.php?rest_route=\/wp\/v2\/posts\/1188\/revisions\/1193"}],"wp:attachment":[{"href":"https:\/\/blog.ray650128.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ray650128.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ray650128.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}