program in java to find least common multiple of two integers
Answers
Answered by
1
Answer:
public class Main {
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;
}
}
}
Output
The LCM of 72 and 120 is 360.
Answered by
3
Answer:
Explanation:
import java.util.*;
public class Brainly
{
static void main()
{
Scanner sc=new Scanner(System.in);
int i,a,b;
System.out.println("Enter 2 integers:");
a=sc.nextInt();
b=sc.nextInt();
for(i=a;i<=a*b;i++)
{
if(i%a==0 && i%b==0)
break;
}
System.out.println("L.C.M.="+i);
}
}
Similar questions