利用欧几里得算法求得最大公约数
作者:互联网
package Euclid;
import java.util.Scanner;
public class Test_Euclid {
//主程序入口
public static void main(String args[]){
Scanner sc1 = new Scanner(System.in);
int num1 = sc1.nextInt();
int num2 = sc1.nextInt();
gcd test = new gcd();
int aim = test.Euclid(num1,num2);
System.out.println(aim);
}
}
//欧几里得算法
class gcd{
int Euclid(int num1,int num2){
while (num2 != 0){
int r = num1 % num2;
num1 = num2;
num2 = r;
}
return num1;
}
}
标签:num1,num2,int,欧几里得,最大公约数,算法,Euclid,sc1,gcd 来源: https://blog.csdn.net/caixiaobai123/article/details/117398855