Write a program to calculate the HCF of two numbers.
Input(First Number, Second Number) | Output |
---|---|
5, 10 | 5 |
9, 19 | 1 |
64, 96 | 32 |
class CalculateHCF
{ public static void main(String s[])
{
int result = calculateHcf( 14, 28 );
System.out.println("The Highest Common Factor is " + result);
}
public static int calculateHcf(int first, int second)
{
//Write a code here to calculate the HCF of two numbers and assign it to result. If required, you can use getFactors method.
}
public static int[] getFactors(int number)
{
//Write code here to get the array containing the factors of the given input number
}
}
Topic: Learn Arrays And Loops