1public class LCMOfTwoNumbers
2{
3 public static void main(String[] args)
4 {
5 int num1 = 85, num2 = 175, lcm;
6 lcm = (num1 > num2) ? num1 : num2;
7 while(true)
8 {
9 if(lcm % num1 == 0 && lcm % num2 == 0)
10 {
11 System.out.println("LCM of " + num1 + " and " + num2 + " is " + lcm + ".");
12 break;
13 }
14 ++lcm;
15 }
16 }
17}
1calculate lcm two numbers in java we can use GCD
2public class LCMUsingGCD
3{
4 public static void main(String[] args)
5 {
6 int num1 = 15, num2 = 25, gcd = 1;
7 for(int a = 1; a <= num1 && a <= num2; ++a)
8 {
9 if(num1 % a == 0 && num2 % a == 0)
10 {
11 gcd = a;
12 }
13 }
14 int lcm = (num1 * num2) / gcd;
15 System.out.println("LCM of " + num1 + " and " + num2 + " is " + lcm + ".");
16 }
17}