java|最大公约数_辗转相除法

public class 最大公约数_辗转相除法 { /** * @param args */ public static int getGreatestCommonDivisorV2(int a, int b) { int big = a > b ? a : b; int small = a < b ? a : b; if (big % small == 0) { return small; } return getGreatestCommonDivisorV2(big % small, small); } public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(getGreatestCommonDivisorV2(25, 5)); System.out.println(getGreatestCommonDivisorV2(100, 80)); }}

    推荐阅读