java中最小公倍数与最大公约数
import java.util.Scanner; /** * Created by Admin on 2017/3/26. */ public class test02 { public static int MinCommon(int a, int b) { int c, m = a * b; if(a<b){ int t=a; a=b; b=t; } if (a % b == 0) return a; else { while (b != 0) { c = a % b; a = b; b = c; } return m/a; } } public static void main(String[] args) { int a=1,b=1; Scanner scanner=new Scanner(System.in); while (a!=0||b!=0){ a=scanner.nextInt(); b=scanner.nextInt(); int result=MinCommon(a,b); System.out.println(result); System.out.println((a*b/result)); } } }
以上是详细介绍java中最小公倍数与最大公约数的详细内容。更多信息请关注PHP中文网其他相关文章!