
Hi,
can any one please share teh code to find the HCF of 2 or 3 numbers??

Here is a java code that finds the hcf of three numbers. You can also find the hcf of two numbers with this code.
import java.util.*;
public class HCFOFNumbers {
public static int hcf(int a, int b) {
if (b == 0)
return a;
else
return hcf(b, a % b);
}
public static int hcf(int a, int b, int c) {
return hcf(hcf(a, b), c);
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter Number 1: ");
int num1 = input.nextInt();
System.out.print("Enter Number 2: ");
int num2 = input.nextInt();
System.out.print("Enter Number 3: ");
int num3 = input.nextInt();
int hcfOfNumbers = HCFOFNumbers.hcf(num1, num2, num3);
System.out.println("HCF of three numbers " + num1 + "," + num2
+ " and " + num3 + " is: " + hcfOfNumbers);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.