You are on page 1of 1

import java.util.

*;
public class Hifact
{
int a, b, hcf, lcm;
public Hifact()
{
a = b = hcf = lcm = 0;
}
void getData()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter 1st number : ");
a = sc.nextInt();
System.out.print("Enter 2nd number : ");
b = sc.nextInt();
}
void change()
{
if(a > b)
{
int t = a; a = b; b = t;
}
}
int recHcf(int x, int y)
{
if(y == 0)
return x;
else return recHcf(y, x % y);
}
int fn_lcm(int x, int y, int z)
{
return (x * y) / z;
}
void result()
{
hcf = recHcf(a, b); lcm = fn_lcm(a, b, hcf);
System.out.println("Hcf : " + hcf);
System.out.println("Lcm : " + lcm);
}
public static void main(String args[])
{
Hifact obj = new Hifact();
obj.getData(); obj.change(); obj.result();
}
}

You might also like