Created
March 17, 2010 16:07
-
-
Save shaobin0604/335393 to your computer and use it in GitHub Desktop.
最大公约数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Test { | |
| public static void main(String[] args) { | |
| int a = 165, b = 55; | |
| System.out.printf("%d 和 %d 的最大公约数是: %d\n", a, b, gcd(a, b)); | |
| } | |
| public static int gcd(int a, int b) { | |
| // suppose a > b; | |
| int r = a % b; | |
| while (r != 0) { | |
| a = b; | |
| b = r; | |
| r = a % b; | |
| } | |
| return b; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment