Find GCD of Two Numbers using Recursion – Java Code

How to find GCD of two numbers. In this tutorial, I am going to discuss multiple approaches to find GCD of two numbers using Recursion.

Given two input integers, we have to write a code to find GCD of two numbers using recursion.

For example:

Input  n1 : 36    n2 : 54

Output 18

Explanation :

The divisiors of 36 are 1, 2, 3, 4, 6, 9, 12, 18, 36  and the divisiors of 54 are 1,  2,  3,  6,  9,  18,  27,  54.

Common divisors are 1, 2, 3, 6, 9, 12 and 18.

The GCD (Greatest Common Divisior) for 36 and 54 is 18.

For this program, I assume you are familiar with the concept of recursion. If you don’t know about recursion then check my previous post on recursion vs iteration.

Find First Non-repeating Character in a String – Java Code

Write a java program to find first non-repeating character in a string. Given an input string, Write a java code to find first non-repeating character in a string.

For example –

i) Input string – java
Output – j (j is the first non-repeating character)

ii) Input string – web rewrite
Output – b (b is the first non-repeating character)