//求两个整数的最大公约数和最小公倍数
public class gongyue
{
   public static void main(String args[])
   {
       int num1,num2;
       System.out.println("请输入第一个数:");
       num1=Integer.parseInt(args[0]);
       System.out.println("请输入第二个数:");
       num2=Integer.parseInt(args[1]);
       System.out.println("所求两数:"+num1+"和"+num2+"的最大公约数是:"+maxx(num1,num2)+",最小公位数是:"+minx(num1,num2));
    }
    public static int maxx(int a,int b)
    {
       if(a==0)
           return b;
       if(b==0)
           return a;
       if(a>b)
       {
           swap(a,b);
       }
       int c;
       for(c=a%b;c>0;c=a%b)
       {
           a=b;
           b=c;
       }
       return b;
     }
     public static int minx(int m,int n)
     {
          return m*n/maxx(m,n);
     }
     public static void swap(int a,int b)
     {
          int c=a;
          a=b;
          b=c;
     }
}

相关文章:

  • 2021-07-27
  • 2021-08-01
  • 2021-11-25
  • 2021-12-28
  • 2022-02-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-09
  • 2021-11-01
  • 2021-07-18
  • 2022-02-25
  • 2021-11-24
  • 2021-11-28
相关资源
相似解决方案