Hey everyone, I recently had the assignment to write a recursive program to calculate greatest common denominator.
I barely understood recursion when our instructor explained it to us.
I understood how it works and calling on itself I am just bad at implementing it.
I think I almost got my program to run correctly. it does everything but print out the answer. It will take my two numbers but will not do anything after. Any help would be greatly appreciated.
import TerminalIO.KeyboardReader;
public class gcd
{
public static void main(String []args)
{
KeyboardReader reader = new KeyboardReader();
int gcd;
int a;
int b;
System.out.print("Enter your first number-");
a = reader.readInt();
System.out.print("Enter your second number-");
b = reader.readInt();
}
public static int gcd(int a, int b)
{
if(a > b)
return gcd(b, a % b);
else
return gcd(a, b % a);
}
}
Thanks