class MyException extends Exception{
private static final long serialVersionUID = 1L;
String message;
public MyException(String ErrorMessagr){
message = ErrorMessagr;
}
public String getMessage(){
return message;
}
}
public class ZDGYS{
static int zdgy(int x,int y)throws MyException{
if(x<0||y<0){
throw new MyException("这两个数都不能小于0。");
}
int a=1;
if(x>y){
if(x%y==0){
a=y;
}else for(int i=2,j=0;i<=y/2;i++){
if(y%i==0){
j=y/i;
if(x%j==0){
a=j;
break;
}
}
}
} else{
if(y%x==0){
a=x;
}else for(int i=2,j=0;i<=x/2;i++){
if(x%i==0){
j=x/i;
if(y%j==0){
a=j;
break;
}
}
}
}
return a;
}
public static void main(String[]args){
try{
int A = zdgy(390,130);
System.out.println("最大公约数为:"+A);
}catch(MyException a){
System.out.println(a.getMessage());
}
}
}