H.C.F. or G.C.D. Of Two Number Program in Java

java program to calculate HCF of two number

In this tutorial, we are going to learn writing java program to calculate the Highest Common Factor of two numbers. Our program will take two numbers as the inputs given by the user and returns the h.c.f. of given numbers.

For example, for the inputs of the two numbers 4 and 6. Our program will return ‘2’ as an output.

Java Program to calculate HCF/GCD of two Numbers

Output

HCF Program in java

Explanations

For inputs 6 and 2, the program is finding the highest factor that is common in both 6 and 2.
The factor of 6 is 1,2,3 and the factor of 2 is 1,2. The highest factor common in
both is 2.