天天看點

最小公倍數算法java_判斷兩個數的最小公倍數算法JAVA代碼

package suxueyuanli;

import java.util.Scanner;

public class Lcm {

public static void main(String[] args) {

System.out.println("請輸入兩個正整數:");

@SuppressWarnings("resource")

Scanner scan = new Scanner(System.in);

@SuppressWarnings("resource")

Scanner scan2=new Scanner(System.in);

int x=scan.nextInt();

int y=scan2.nextInt();

int sum=0;

for(int i=1;i>0;i++) {

sum=i*y;

if(sum%x==0) {

System.out.println(+x+"與"+y+"的最小公倍數為"+sum);

break;

}

}

}

}