Java Program to Find HCF of Two Numbers

15 Likes 3 Comments
Java Program to Calculate HCF of two numbers

Hello Shouters !! Today we will understand the Java program to Find HCF of two numbers.

We will use two methods to find the HCF of Two Numbers, the first one will be without taking the function and the other one will be using the functions.

What is HCF?

HCF stands for Highest Common Factor and is the highest common divisor between two numbers. In simple terms, if we have two numbers then the biggest number that can divide both the numbers completely is know as the HCF of the number.

1. First Method- Without Function

In this method, we will only take two numbers and will do the manipulation of the data to get the HCF.

Output – Enter the first number 90 Enter the Second Number 75 HCF of the given numbers is 15

2. Second Method- Using Functions

In this method, we will be using a function to calculate the HCF of the two numbers.

Output – Enter the first number 90 Enter the Second Number 75 HCF of the given numbers is 15

It is very good to know two Java program to find the HCF of two numbers for placement interviews and general knowledge.

We daily add Multiple Choice Questions for placement preparation questions and technical interview preparation on the Instagram page. Check the Instagram account:

Frequently Asked Questions-

What is HCF of two numbers?

HCF stands for highest Common Factor and is the highest common divisor in the two numbers.

Is GCD and HCF different?

No, GCD stands for Greatest Common divisor and HCF stands for Highest Common Factor both are same and can be find using same program.

What is the HCF of two prime numbers?

Prime Numbers are only divisible by 1 and the number itself. So, the HCF of two prime numbers is always 1.

Is the program important from placement perspective?

Yes, it is very important from placement view and asked in many major companies.

Recommended Posts –

  1. Introduction and Installation of Java on Windows
  2. Program to add two numbers in Java
  3. Java Program to Calculate the Factorial of a number.
  4. Java Program to Swap two numbers
  5. Java Program to Check Whether a Number is an Even or Odd

You might like


About the Author: Akshay sharma

Hey Shouters!!. I am the CEO of I have completed the Electronics and Communication Engineering from Guru Nanak Dev University, Amritsar, Punjab. I Cleared TCS Codevita with a rank of 5,035. Got a Job Offer from TCS, India through it. Also, Got Job offer from SAP Labs, India as a Scholar. I will be joining soon. The aim of our website is to provide programming knowledge in simplest way.


  1. Please let me know if you’re looking for a author for your blog.

    You have some really great posts and I think I would be a good asset.
    If you ever want to take some of the load off, I’d
    really like to write some content for your blog in exchange for a link
    back to mine. Please blast me an email if interested. Thank

    Here is my blog :: CBD for sale

Leave a Reply

Your email address will not be published. Required fields are marked *

Close Bitnami banner