Write a Java program to calculate and print the LCM of two numbers entered by user.
Answers
Answered by
4
hey mate
here is the solution...
import java.util.*;
class Lcm
{
public static void main (String args [])
{
Scanner sc=new Scanner (System.in);
System.out.println("enter the two numbers");
int a=sc.nextInt();
int b=sc.nextInt();
int lcm=0;
for(int i=1; ;i++)
{
if(i%a==0 && i%b==0)
{
lcm=i;
break;
}
}
System.out.println("lcm:"+lcm);
}
}
LIKE AS MUCH AS YOU CAN!!!!
Anonymous:
just two likes
Answered by
1
Explanation:
import java.util.*;
class Lcm
{
public static void main (String args [])
{
Scanner sc=new Scanner (System.in);
System.out.println("enter the two numbers");
int a=sc.nextInt();
int b=sc.nextInt();
int lcm=0;
for(int i=1; ;i++)
{
if(i%a==0 && i%b==0)
{
lcm=i;
break;
}
}
System.out.println("lcm:"+lcm);
}
}
HOPE IT WILL HELP YOU
PLEASE MARK ME AS BRAINLIEST AND FOLLOW ME
Similar questions