Answers for "gcd of two numbers using recursion in java"

2

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;
      }
   }
}
Posted by: Guest on February-22-2021

Code answers related to "gcd of two numbers using recursion in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language