Java program to calculate HCF of two numbers
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
In this program, we will read two integer numbers and find the Highest Common Factor (HCF) for both numbers.
Program/Source Code:
The source code to calculate the HCF of two numbers is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we imported the "java.util.Scanner" package to read input from the user. And, we created a public class Main. It contains two static methods CalHcf() and main().
The CalHcf() method is used to calculate the HCF of given numbers and return the result to the calling method.
The main() method is an entry point for the program. And, we read two integer numbers from the user using the nextInt() method. Then we called CalHcf() method to calculate HCF and printed the result.