题解 | #求最小公倍数#

求最小公倍数

https://www.nowcoder.com/practice/feb002886427421cb1ad3690f03c4242

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int m = console.nextInt();
        int n = console.nextInt();
        int result = getCM(m, n);
        System.out.println(result);
    }

    public static int getCM(int m, int n){
        //write your code here......
        int max = Math.max(m, n); //找出最大值
        //在循环中判断出最小公倍数
        for(int i = m; i <= m * n; i++) { 
            if(i % m == 0 && i % n == 0) {
                return i;
            }
        }
        return -1;
    }
}

全部评论

相关推荐

安静的鲸鱼offer...:神仙级别hr,可遇不可求,甚至他可能也是突然有感而发。只能说遇上是件幸事。
秋招开始捡漏了吗
点赞 评论 收藏
分享
牛客41406533...:回答他在课上学,一辈子待在学校的老教授用三十年前的祖传PPT一字一句的讲解,使用谭浩强红皮书作为教材在devc++里面敲出a+++++a的瞬间爆出114514个编译错误来学这样才显得专业
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务