zoukankan      html  css  js  c++  java
  • Java经典编程题50道之六

    输入两个正整数m和n,求其最大公约数和最小公倍数。

    public class Example06 {
        public static void main(String[] args) {
            int a = 1;
            int b = 10;
            int max = f(a, b);
            int min = a * b / max;
            System.out.println("最大公约数:" + max + " 最小公倍数:" + min);
        }

        public static int f(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;
        }
    }

  • 相关阅读:
    SVN客户端的安装和使用
    SVN服务器的安装和使用
    ssh port forwarding
    mysql 索引
    ssh forwarding 配置
    pymongo collection.save 问题
    linux 实现VLAN
    linux 硬件中断调节
    M2Crypto
    python 时间四舍五入
  • 原文地址:https://www.cnblogs.com/qubo520/p/6928053.html
Copyright © 2011-2022 走看看