date: 2018/1/18 14:39:47
求两个数的最大公约数和和最小公倍数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| package com.xiaolan; public class Mian { public static void main(String[] args) { int i = 0; int a = 12; int b = 8; if (a > b) { i = b; } else { i = a; } for (; i > 0; i--) { if (a % i == 0 && b % i == 0) { break; } } int n = (a / i) * (b / i) * i; System.out.println("最大公约数" + i + "\n" + "最小公倍数是" + n); } }
|