Java用递归法求两个数的最大公约数

package com.cn;

import java.util.Scanner;

public class Zuidagongyueshu {

public static int yue(int a, int b) {
	
	int r = a % b;
	if( r == 0 )
	    return b;
	else
		return yue(b,r);
}

public static void main(String[] args) {
	// TODO Auto-generated method stub
	System.out.println("请输入两个整数:");
	Scanner x = new Scanner( System.in );
	int a=x.nextInt();
	int b=x.nextInt();
	System.out.println( yue(a,b) );

}

}

发布了5 篇原创文章 · 获赞 0 · 访问量 205

猜你喜欢

转载自blog.csdn.net/weixin_46424591/article/details/104802177
今日推荐