-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge20.java
More file actions
25 lines (23 loc) · 878 Bytes
/
challenge20.java
File metadata and controls
25 lines (23 loc) · 878 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
import java.util.Scanner;
// Create a program to find the Least Common Multiple (LCM) of two numbers.🚀
public class challenge20 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to LCM!");
System.out.print("Enter the first number: ");
int num1 = sc.nextInt();
System.out.print("Enter the second number: ");
int num2 = sc.nextInt();
int lcm = findLCM(num1, num2);
System.out.println("The LCM of " + num1 + " and " + num2 + " is: " + lcm);
}
public static int findLCM(int num1, int num2) {
int greaterNum = Math.max(num1, num2);
while (true) {
if (greaterNum % num1 == 0 && greaterNum % num2 == 0) {
return greaterNum;
}
greaterNum++;
}
}
}