-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeastCommonMultiple.java
More file actions
30 lines (24 loc) · 886 Bytes
/
Copy pathLeastCommonMultiple.java
File metadata and controls
30 lines (24 loc) · 886 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
28
29
30
import java.util.Scanner;
public class LeastCommonMultiple{
public static void main(String[] args) {
Scanner num = new Scanner(System.in);
System.out.println("Welcome to LCM calculator: ");
System.out.print("Please enter the first number: ");
int first = num.nextInt();
System.out.print("Please enter the second number: ");
int second = num.nextInt();
int yourLcm = myLCM(first, second);
System.out.println("Your LCM number is: " + yourLcm);
}
public static int myLCM(int first , int second){
int i = 1;
while(true){//(i <= second)
int myNumber = first * i ;
if(myNumber % second == 0){
return myNumber ;
}
i++ ;
}
// return 0 ;//Unreacheable In case loop become infinite loop
}
}