Code Below:
import java.util.*;
class hcf_lcm
{
public static void main()
{
Scanner s=new Scanner(System.in);
int x,y,max,i,hcf=1,lcm;
System.out.println("enter nos.");
x=s.nextInt();
y=s.nextInt();
max=Math.max(x,y);
for (i=1;i<=max;i++)
{
if(x%i==0 && y%i==0)
{
hcf=i;
}
}
lcm=hcf*x/hcf*y/hcf;
System.out.println("hcf="+hcf);
System.out.println("lcm="+lcm);
}
}