0
点赞
收藏
分享

微信扫一扫

基于SpringBoot的OA办公管理系统

流沙雨帘 2024-04-03 阅读 12

求最大公约数

代码:

import java.util.Scanner;

public class 第十三题 {
    public static void main(String[] args) {
       /* Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        while (b!=0){
            int c=a%b;
            a=b;
            b=c;
        }
        System.out.println(a);*/
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
       int w= ff(a,b);
        System.out.println(w);
    }
    public static int ff(int a,int b){
        if(b==0){
            return a;
        }
        int c=a%b;
        a=b;
        b=c;
        return ff(a,b);


    }
}
举报

相关推荐

0 条评论