**Question 37 : Write a program in Java to find the Lowest Common Multiple (L.C.D.) of two numbers entered by the user :**

**Java Program :**

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);

}

}

public class ques

ReplyDelete{

public void main(int a, int b)

{

int l=a>b?a:b;

int lcm=1;

for(int i=l; i<=a*b; i++)

{

if(i%a==0 && i%b==0)

{

lcm=i;

break;

}

}

System.out.println(lcm+ " is lcm");

}

}

you are loser not good program

DeleteThis is a simple prg in bluej environment. Nice

Deletekindly also give outputs as well thanks

ReplyDeletehi u guys dont know programming stupid skankwad .....

ReplyDeleteimport java.io.*;

ReplyDeleteclass LcmMethod_2

{

public static void main()throws IOException

{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int a,b,max,min,x,lcm=1;

System.out.print("Enter the 1st number : ");

a=Integer.parseInt(br.readLine());

System.out.print("Enter the 2nd number : ");

b=Integer.parseInt(br.readLine());

if(a>b)

{

max=a;

min=b;

}

else

{

max=b;

min=a;

}

/*

To find the maximum and minimum numbers, you can also use

int max=a>b?a:b;

int min=a<b?a:b;

*/

for(int i=1;i<=min;i++)

{

x=max*i; //finding multiples of the maximum number

if(x%min==0) //Finding the multiple of maximum number which is divisible by the minimum number.

{

lcm=x; //making the first multiple of maximum number which is divisible by the minimum number, as the LCM

break; //exiting from the loop, as we don’t need anymore checking after getting the LCM

}

}

System.out.println("L.C.M. = "+lcm);

}

}

I HAVE 11 ERRORS.. WHAT TO DO...?

ReplyDeleteUSE THIS PROGRAM...

Deleteimport 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);

}

}

I DON'T UNDERSTAND YOUR CODING.. PLEASE GIVE SOME OTHER METHODS..

ReplyDeleteVery much useful article. Kindly keep blogging

ReplyDeleteJava Training in Chennai

Java Online Training India