LCM(Least Common Multi)总是大于或等于这两个数字的更大。 因此,如果我们发现LCM &的话,我们首先会核实,如果发现LCM &,则人数越多,数字就越多,只有两个数字的LCM。
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter the first Number : ");
int number1 = scan.nextInt();
System.out.print("Enter the second number : ");
int number2 =scan.nextInt();
int multiple;
if(number1 >= number2) {
multiple = number1;
} else {
multiple = number2;
}
Boolean loopContinue = true;
while(loopContinue) {
if(multiple % number1 == 0 && multiple % number2 == 0) {
System.out.println("LCM of Two Numbers is " + multiple);
loopContinue = false;
}
multiple++;
}
}
}