-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCM.java
More file actions
27 lines (23 loc) · 792 Bytes
/
LCM.java
File metadata and controls
27 lines (23 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package challanges;
import java.util.Scanner;
public class LCM {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Welcome to LCM Calculator");
System.out.println("Enter First Number : ");
int fNum = input.nextInt();
System.out.println("Enter Second Number: ");
int sNum = input.nextInt();
int result = LCMResult(fNum, sNum);
System.out.println("LCM of given two number is : " + result);
}
public static int LCMResult(int fNum, int sNum) {
int maxNum = (fNum > sNum) ? fNum : sNum;
while (true) {
if ((maxNum % fNum == 0) && (maxNum % sNum == 0)) {
return maxNum;
}
maxNum++;
}
}
}