Help with GCD
I am trying to write a method for a recursive method with the method signature as:
publicint gcdRec(int num1,int num2)
this is what i have written:
publicclass GCD
{
publicint gcdRec(int num1,int num2)
{
if (num2 == 0)
return num1;
else
return gcdRec(num2, num1%num2);
}
}
class Test//class to test the method
{
publicstaticvoid main(String [] args)
{
int x = 5;
int y = 10;
System.out.println("The GCD of" + x +"and" + y +"is" + GCD.gcdRec(x,y));
}
}
After compliation, i encounter this error: non-static method gcdRec(int,int) cannot be referenced from a static context. How do i change the class to test the method? Secondly, is my recursive mehtod gcdRec correct? Pls guide.

