Find GCD of two numbers in java using recursion code example

Example: Find GCD of two numbers in java using recursion

// Find GCD of two numbers in java using recursion
public class GCDUsingRecursion
{
   public static void main(String[] args) 
   {
      int number1 = 898, number2 = 90;
      int gcd = gcdRecursion(number1, number2);
      System.out.println("G.C.D of " + number1 + " and " + number2 + " is " + gcd);
   }
   public static int gcdRecursion(int num1, int num2)
   {
      if(num2 != 0)
      {
         return gcdRecursion(num2, num1 % num2);
      }
      else
      {
         return num1;
      }
   }
}

Tags:

Misc Example