Computer Science, asked by nike14, 1 year ago

write a program in Java to find the LCM of two numbers

Answers

Answered by aman1091
10
⭐hey there!!

=] To find LCM of two numbers using While loop:

====>

public class LCM {
public static void main(String[] args) {

int n1 = 72, n2 = 120, lcm;

// maximum number between n1 and n2 is stored in lcm
lcm = (n1 > n2) ? n1 : n2;

// Always true
while(true)
{
if( lcm % n1 == 0 && lcm % n2 == 0 )
{
System.out.printf("The LCM of %d and %d is %d.", n1, n2, lcm);
break;
}
++lcm;
}
}
}

______________________________________

⭐hope it will help u

nike14: didn't get this one
nike14: Plz explain
nike14: who whole program please make it again and simple
nike14: OK byd
Similar questions