-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCM.java
More file actions
44 lines (33 loc) · 955 Bytes
/
Copy pathLCM.java
File metadata and controls
44 lines (33 loc) · 955 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* LCM
* LCM of 2 integers is the smallest positive integer that is perfectly divisible by both numbers without a remainder.
* LCM cannot be less than the largest number
*/
public class LCM {
public static void main(String[] args) {
findLcm(72, 120);
}
static void findLcm(int a, int b){
int lcm = (a > b)? a : b;
while(true){
if(lcm%a == 0 && lcm % b == 0){
//System.out.println(lcm);
System.out.printf("LCM of %d and %d is %d ",a,b,lcm);
break;
}
++lcm;
}
}
static long lcmArr(int[] arr){
int max = arr[0];
for(int i=0;i < arr.length;i++){
//get the largest value in the array
if(arr[i] > max){
max = arr[i];
}
if(arr[i] % max == 0){
}
}
return 0;
}
}