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**

**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.