Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/purvgwtw/public_html/tutorials/common.php on line 7
Find HCF of Three Numbers
Sponsered Links
Sponsered Links

Find HCF of Three Numbers

Here we are going to find the hcf of three numbers.

import java.util.*;

public class HCFOFThreeNumbers {
    public static int findHcf(int a, int b) {
        if (b == 0)
            return a;
            return findHcf(b, a % b);

    public static int findHcf(int a, int b, int c) {

        return findHcf(findHcf(a, b), c);


    public static void main(String[] args) {
        Scanner input = new Scanner(;
        System.out.print("Enter Number 1: ");
        int n1 = input.nextInt();
        System.out.print("Enter Number 2: ");
        int n2 = input.nextInt();
        System.out.print("Enter Number 3: ");
        int n3 = input.nextInt();
        int hcfOfNumbers = HCFOFNumbers.findHcf(n1, n2, n3);
        System.out.println("HCF of three numbers " + n1 + "," + n2
                + " and " + n3 + " is: " + hcfOfNumbers);

Sponsered Links
Latest Updates
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2014 PURVACOMPUTERS.COM All Right Reserved