Java Source code on Printing the Greatest Common Divisor (GCD) using Recursion

Below is the Java sample code on printing the GCD of the 2 numbers in recursion. The GCD recursive methods is quite an easy problem to program if you know its recursive definition. Since recursion is basically has a base case and general case, the program will stop on looping if it meets the condition of the base case and return a value of the general case if not. To have a glimpse of the recursive formula, here it is for you to evaluate and see how I transform it into java language.

GCD Recursive Definition:

Given two integers x and y

{ x if y==0
GCD(x, y) =
{ y if y != 0

Below is the following code for the recursive definition above.

Java Source Code on Printing the Greatest Common Divisor or GCD in Recursion

Java Books

Other Java Source Code Examples

Java Simple Codes for Beginners
What is a Java Scanner Class and How to Use it?
Java Program: How to Use Switch Statement in Java
Java source codes on outputting Asterisk in Different Forms Using Recursion
Java Source Code: A Recursive Asterisk Diamond Shape
Java Source code on Adding Numbers inside the Array using For Loop
Java Source codes on Adding numbers inside the Array Using Recursion
Java Source Code: How to Sort Numbers in Bubble Sort Using Recursion
Java Source Code: Sort Numbers using Selection Sort
Java Source Code on Linear Search Using Recursion
Java Source Code: Binary Search in Recursion
Java Source code: How to Print a String Backward using Recursion
Java source code: How to Output the Answer of the Integer X to the Power Y
Java Source Code: How to make a Program that will determine a Person’s Salutation and Current Age
Java Source Code: Recursive Snow Flakes