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


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

     1 import java.util.Scanner;
     2 
     3 
     4 public class Algorithm_Game_06 {
     5     public static void main(String[] args) {
     6         Scanner s = new Scanner(System.in);
     7         int m = s.nextInt();
     8         int n = s.nextInt();
     9         System.out.println("最大公约数:"+f(m, n));
    10         System.out.println("最小公倍数:"+m(m, n));
    11     }
    12     public static int f(int m,int n){
    13         int c = m%n;
    14         return c==0? n: f(n,c);
    15     }
    16     public static int m(int m,int n){
    17          return (m*n/f(m,n));
    18     }
    19 }
  • 相关阅读:
    希尔排序
    代理模式
    快速排序
    插入排序
    各种排序算法的稳定性和复杂度
    简单选择排序
    冒泡排序
    流程图
    PLAY学习【未完】
    项目之maven心得
  • 原文地址:https://www.cnblogs.com/elleniou/p/3283497.html
Copyright © 2020-2023  润新知