标签:
package Test3;
public class MyTool {
public static int GetMaxDivide(int num1, int num2) {
if (num1 < num2) {
//交换num1,num2
int temp;
temp = num1;
num1 = num2;
num2 = temp;
}
if (num2 != 0) {
return GetMaxDivide(num2, num1 % num2);
}
else{
return num1;
}
}
}
package Test3;
import java.util.Scanner;
public class Test3Demo {
public static void main(String[] args) {
System.out.println("请输入x,y两个正整数:");
Scanner in=new Scanner(System.in);
int x=in.nextInt();
int y=in.nextInt();
//使用方法
int result=MyTool.GetMaxDivide(x, y);
System.out.println("两个数的最大公约数是:"+result);
}
}
标签:
原文地址:http://www.cnblogs.com/chengxiaodong/p/5579246.html