The two numbers are accepted as Commamnd line arguements and GCD of those numbers are found using a recursive method.
Recursive method to find GCD of two numbers
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));
}
}
NormR1 563 Posting Sage Team Colleague
raj26061990 0 Newbie Poster
raj26061990 0 Newbie Poster
raj26061990 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.