最大公约数和最小公倍数

来源:互联网 发布:计算机二级c语言好考吗 编辑:程序博客网 时间:2024/06/05 21:24


import java.util.Scanner;

 class Gcd{
  
     public int f(int a,int b)
    {
     int r=a%b;
     while(r!=0)
     {
      a=b;
      b=r;
      r=a%b;
     }
     return b;
    }
}
 class God extends Gcd{
 
  public int f(int a,int b)
  {
   int gcd=super.f(a, b);
   int god=a*b/gcd;
   return god;
  }
 }
public class Main {
   public static void main(String []args){
    Gcd A=new Gcd();
    God B=new God();
    System.out.println(A.f(3,20));
    System.out.println(B.f(100,20));
   }
}

0 0
原创粉丝点击