Java Program to find GCD of Two Numbers

The Greatest Common Divisor (GCD) is also known as the Highest Common Factor (HCF), or Highest Common Divisor (HCD), or Greatest Common Factor (GCF), or Greatest Common Measure (GCM). In this article we will show you, How to write a Java Program to find GCD of Two Numbers using For Loop, While Loop, and recursive method.

According to Mathematics, GCD of two or more integers is the largest positive integer that divides the given integer without any remainder. For example, GCD of 8 and 12 is 4 because, both 8 and 12 are divisible by 1, 2, and 4. The largest positive integer among the factors 1, 2, and 4 is 4.

NOTE: In order to find the Greatest Common Divisor, we have to pass at least one non-zero value.

Java Program to find GCD of Two Numbers using For Loop

This program allows the user to enter two positive integer values. Next, it will calculate the Highest Common Factor (HCF) or GCD of those two values using For Loop.