-
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) · 737 Bytes
/
Copy pathLcm.java
File metadata and controls
27 lines (23 loc) · 737 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
import java.util.Scanner;
public class Lcm {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.err.println("welcome to calculate lcm of two numbers");
System.out.println("please enter your number:");
int first = input.nextInt();
System.out.println("please enter your number:");
int second = input.nextInt();
int lcm = lcm(first,second);
System.out.println("lcm is:" + lcm);
}
public static int lcm(int first,int second) {
int i = 1;
while(true) {
int factor = first*i;
if(factor % second ==0) {
return factor;
}
i++;
}
}
}