标签:new tin ann main 输入 exti 约数 整数 style
public class GCD_and_LCM {
public static void main(String args[]){
System.out.println("请输入两个整数:");
Scanner s=new Scanner(System.in);
int a=s.nextInt();
int b=s.nextInt();
GCD_and_LCM gl=new GCD_and_LCM();
System.out.println(a+"和"+b+"的最大公约数和最小公倍数分别为:");
System.out.println(gl.gcd(a,b));
System.out.println(gl.lcm(a, b));
}
public int gcd(int a,int b){
if(b==0){
return a;
}
else{
while(b!=0){
int r=a%b;
a=b;
b=r;
}
return gcd(a,b);
}
}
public int lcm(int a,int b){
return a*b/gcd(a,b);
}
}
标签:new tin ann main 输入 exti 约数 整数 style
原文地址:https://www.cnblogs.com/MuXiao-DJT/p/8783357.html