We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4a2a951 commit 8d3dcafCopy full SHA for 8d3dcaf
challenge20.java
@@ -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
+}
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments