0

The two numbers are accepted as Commamnd line arguements and GCD of those numbers are found using a recursive method.

Edited by raj26061990: small mistake

class GCD
{
int gcd(int m,int n)
{
if(n==0)
return m;
else if(n>m)
return gcd(n,m);
else
return gcd(n,m%n);
}
public static void main(String[] args)
{
int num1=Integer.parseInt(args[0]);
int num2=Integer.parseInt(args[1]);
GCD obj=new GCD();
System.out.println("GCD of "+num1+" and "+num2+" is "+obj.GCD(num1,num2));
}
}
2
Contributors
4
Replies
14
Views
6 Years
Discussion Span
Last Post by raj26061990
0

If your going to post code examples, at least you could check if it works.

CD_Finder.java:18: cannot find symbol
symbol  : method GCD(int,int)
location: class GCD_Finder.GCD
System.out.println("GCD of "+num1+" and "+num2+" is "+obj.GCD(num1,num2));
                                                         ^
1
class GCD
{
int gcd(int m,int n)
{
if(n==0)
return m;
else if(n>m)
return gcd(n,m);
else
return gcd(n,m%n);
}
public static void main(String[] args)
{
int num1=Integer.parseInt(args[0]);
int num2=Integer.parseInt(args[1]);
GCD obj=new GCD();
System.out.println("GCD of "+num1+" and "+num2+" is "+obj.gcd(num1,num2));
}
}
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.