package di5章;
import java.util.Scanner;
public class Topgys {
public static void main(String[] args) {
Topgys hello=new Topgys();
Scanner input=new Scanner(System.in);
System.out.println("shuru di yi ge shu : ");
int n1=input.nextInt();
System.out.println("shuru di er ge shu : ");
int n2=input.nextInt();
int zdgys=hello.gys(n1, n2);
System.out.println(n1+" and "+n2+" 的最大公约数是: "+zdgys);
}
public int gys(int n1,int n2){
int i=2;
int zdgys=1;
while(i<=n1&&i<=n2){
if(n1%i==0&&n2%i==0){
zdgys=i;
i++;
}
}
return zdgys;
}
}
微笑听雨
相关分类