import java.util.*;
public class HCFOFThreeNumbers {
public static int findHcf(int a, int b) {
if (b == 0)
return a;
else
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.in);
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);
}
}
|