
accept two numbers and print their hcf

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 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();
int hcfONums = HCFOFNumbers.hcf(num1, num2);
System.out.println("HCF of two numbers " + num1 + "," + num2+ " is: " + hcfONums);
}
}
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.