Java Program to find the HCF of two numbers given by user.
import java.util.*;
public class HelloWorld {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
int hcf=0;
while(a!=0 && b!=0)
{
if(a>b)
{
a=a-b;
hcf=b;
}
else
{
b=b-a;
hcf=a;
}
}
System.out.println(hcf);
}
}