Friday 6 January 2012

LCM Program In java for two Numbers


/*
  *LCM.java
  * Author Mahesh-cse-b520
  *created on 30/12/2011
  *LCM Of two Numbers
  */
 import java.lang.*;
class LCM
{
public static void main(String args[])
{
int a,b,gcd,lcm;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
gcd=GCD1(a,b);
lcm=(a*b)/gcd;
System.out.println("LCM is"+lcm );
}
public static int GCD1(int x,int y)
{
if(x>y&&y==0)
return x;
if(x<y&&x==0)
return y;
if(x>y)
return GCD1(y,x%y);
if(x<y)
return GCD1(x,y%x);
if(x==y)
return 0;
return 0;
}

}

No comments:

Post a Comment