New course! Every coder should learn Generative AI!
Try a free lesson+ 9
Try first and show attempts if getting any problem.
+ 1
Alpha Arun please do not post your homework here. The community is not here to do it for you.
Thanks and happy coding.
https://www.sololearn.com/discuss/1316935/?ref=app
0
import java.util.Scanner ;
public class MyClass
{
static int hcf(int x,int y) {
int a=x; int t;
int b=y;
if(a<b)
{
while(b!=0)
{
t=b;
b=a%b;
a=t;
}
return a;
}
else
{
while(a!=0)
{
t=a;
a=b%a;
b=t;
}
return b;
}
}
public static void main(String[ ] args)
{ Scanner s=new Scanner(System .in);
int a=s.nextInt();
int b=s.nextInt();
MyClass d=new MyClass();
int h=hcf(a,b);
System .out.println("hcf="+h);
System .out.println("lcm="+((a*b)/h));
}
}