最大公約數

public class Gcb {

private static int gcb(int a,int b){
    if(a%b==0){
        return b;
    }else{
        return gcb(b, a%b);
    }
}

public static void main(String[] args) {
    System.out.println("輸入兩個數,以回車隔開");
    int a = new Scanner(System.in).nextInt();
    int b = new Scanner(System.in).nextInt();
    int c;
    if(b>a){
        c = a;
        a = b;
        a = c;
    }
    System.out.println("a:"+a+",b:"+b+",最大公約數爲:"+gcb(a, b));
    main(args);
}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章