Write a program to calculate HCF and LCM of two numbers.
Answers
Answered by
4
import java.util.Scanner;
public class Hcf_Lcm
{
public static void main(String args [])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter two number: ");
int a = sc.nextInt();
int b = sc.nextInt();
int x = a;
int y = b;
while(b != 0)
{
int t = b;
b = a%b;
a = t;
}
int hcf = a;
int lcm = (x*y)/hcf;
System.out.print("HCF = "+hcf);
System.out.print("\nLCM = "+lcm);
sc.close();
}
}
Similar questions