原版
代码语言:javascript
复制import java.util.Scanner;
public class studying {
private static int euclid(int a,int b){
while(b!=0){
int r=a%b;
a=b;
b=r;
}
return a;
}
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int a=input.nextInt(),b=input.nextInt();
System.out.println(euclid(a,b));
}
}
函数递归调用版本
代码语言:javascript
复制import java.util.Scanner;
public class studying {
private static int euclid(int a,int b){
if(a%b==0)
return b;
return euclid(b,a%b);
}
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int a=input.nextInt(),b=input.nextInt();
System.out.println(euclid(a,b));
}
}