lcm program on java ??????
Answers
Answered by
1
import java.io.*;
class lcm
{
static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a,b,i;
int c=0;
System.out.print("Enter the first number : ");
a=Integer.parseInt(br.readLine());
System.out.print("\n");
System.out.print("Enter the second number : ");
b=Integer.parseInt(br.readLine());
System.out.print("\n");
c=a*b;
int d=c;
for(i=1;i<=c;i++)
{
if(i%a==0 && i%b==0 && i<d)
d=i;
}
System.out.println("The L.C.M : "+d);
}
}
hey mate
hope this helps
class lcm
{
static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a,b,i;
int c=0;
System.out.print("Enter the first number : ");
a=Integer.parseInt(br.readLine());
System.out.print("\n");
System.out.print("Enter the second number : ");
b=Integer.parseInt(br.readLine());
System.out.print("\n");
c=a*b;
int d=c;
for(i=1;i<=c;i++)
{
if(i%a==0 && i%b==0 && i<d)
d=i;
}
System.out.println("The L.C.M : "+d);
}
}
hey mate
hope this helps
narendramodhi724:
thank you so much
Answered by
1
Answer:
This is a simple program to find the LCM of two numbers.
Explanation:
public class Main {
public static void main(String[] args) {
int n1 = 72, n2 = 120, lcm;
lcm = (n1 > n2) ? n1 : n2;
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;
}
}
}
Similar questions
Social Sciences,
7 months ago
Social Sciences,
7 months ago
English,
1 year ago
Science,
1 year ago
Math,
1 year ago
Biology,
1 year ago