编程语言
首页 > 编程语言> > java 求最大公倍数

java 求最大公倍数

作者:互联网

package com.oop;

import java.util.Scanner;

public class Demo4 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int n = sc.nextInt();
		int cm = getCM(m, n);
		System.out.println(cm);
		sc.close();
		
	}
	
	public static int getCM(int m, int n) {
		for(int i = m>n?m:n; i <= m*n; i++) {
			if(i % m == 0 && i % n == 0) {
				return i;
			}
		}
		return -1;
	}
}

标签:java,最大,cm,公倍数,System,int,sc,public,Scanner
来源: https://www.cnblogs.com/my-blog-site/p/16392160.html