第二次作业
import java.util.Scanner;
public class demo {
/**
* @param args
* 3137102245
* 许聪林
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
System.out.println("请输入两个整数:");
int a=0;
int b=0;
try
{
a=s.nextInt ();
b=s.nextInt();
}
catch (Exception e)
{
// TODO: handle exception
System.out.println("无公约数!");
}
MaxDivisor m=new MaxDivisor(a,b);
}
}
public class MaxDivisor{
int A;
int B;
int res;
public MaxDivisor(int a,int b){
if(a>0 && b>0)
{
A=a;
B=b;
res = A % B;
}
while(res!=0)
{
A=B;
B=res;
res=A % B;
}
System.out.println(B);
}
}