最小公倍数----最大公约数
2018-03-26 21:29
225 查看
package com.xjj.algorithm; import java.util.Scanner; public class Gcd { //欧几里得算法求最大公约数 public int gcd(int m, int n){ if (n == 0) return m; return gcd(n, m % n); } //最小公倍数 public int lcm(int m, int n){ return m * n /gcd(m, n); } public static void main(String[] args) { System.out.println("输入两个数: "); Scanner sc = new Scanner(System.in); int m = sc.nextInt(); int n = sc.nextInt(); Gcd gcd = new Gcd(); System.out.println("最大公约数为: " + gcd.gcd(m, n)); System.out.println("最小公倍数为: " + gcd.lcm(m, n)); } }
相关文章推荐
- 最大公约数与最小公倍数
- C/C++训练1---最大公约数与最小公倍数
- 最大公约数和最小公倍数的问题
- C/C++训练1---最大公约数与最小公倍数
- 10_输入两个正整数m和n,求其最大公约数和最小公倍数
- c++实验7-最大公约数和最小公倍数
- C++实验7-最大公约和和最小公倍数
- JAVA :最小公倍数与最大公约数
- 递归:最小公倍数和最大公约数求解
- 最小公倍数,最大公约数
- 最大公约数与最小公倍数
- 最小公倍数和最大公约数计算
- 第3周项目3输出最大公约数最小公倍数
- 两个数的乘积等于其最大公约数与最小公倍数的乘积,怎么证明?
- 输入两个正整数,求它们的最大公约数和最小公倍数.
- C/C++训练1---最大公约数与最小公倍数
- 最大公约数与最小公倍数
- C++作业7—最大公约和和最小公倍数/特殊三位数
- 最大公约数和最小公倍数
- 最大公约数与最小公倍数