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;
	}
}
posted @ 2022-06-20 09:17  wjxuriel  阅读(72)  评论(0)    收藏  举报