Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8d3dcaf

Browse files
🍵
1 parent 4a2a951 commit 8d3dcaf

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎challenge20.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.Scanner;
2+
3+
// Create a program to find the Least Common Multiple (LCM) of two numbers.🚀
4+
public class challenge20 {
5+
public static void main(String[] args) {
6+
Scanner sc = new Scanner(System.in);
7+
System.out.println("Welcome to LCM!");
8+
System.out.print("Enter the first number: ");
9+
int num1 = sc.nextInt();
10+
System.out.print("Enter the second number: ");
11+
int num2 = sc.nextInt();
12+
int lcm = findLCM(num1, num2);
13+
System.out.println("The LCM of " + num1 + " and " + num2 + " is: " + lcm);
14+
}
15+
16+
public static int findLCM(int num1, int num2) {
17+
int greaterNum = Math.max(num1, num2);
18+
while (true) {
19+
if (greaterNum % num1 == 0 && greaterNum % num2 == 0) {
20+
return greaterNum;
21+
}
22+
greaterNum++;
23+
}
24+
}
25+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /