两个整数的最小公倍数及最大公因数

import java.util.*;
public    class  hello { 
public static void main(String[] args) {
int     a ,b,m;
Scanner s = new Scanner(System.in);
System.out.print( "键入一个整数: "); 
a = s.nextInt();
System.out.print( "再键入一个整数: "); 
b = s.nextInt();
      lifs cd = new lifs();
      m = cd.lifs(a,b);
      int n = a * b / m;
      System.out.println("最大公约数: " + m);
      System.out.println("最小公倍数: " + n);
} 
}
class lifs{
public int lifs(int x, int y) {
     int t;
     if(x < y) {
      t = x;
      x = y;
      y = t;
     }  
     while(y != 0) {
      if(x == y) return x;
      else {
       int k = x % y;
       x = y;
       y = k;
      }
     }
     return x;
}
}
 
posted @ 2018-04-10 21:12  努力girl  阅读(331)  评论(1编辑  收藏  举报