
java program for finding LCM and HCF

Hello,
Code is below:
public class MathsDemo {
public static void main(String[] args) {
MathsDemo demo = new MathsDemo();
System.out.println("H.C.F./G.C.D.: " + demo.gcd(12, 16));
System.out.println("L.C.M.: " + demo.lcm(12, 16));
}
int lcm(int a, int b) {
return (a * b / gcd(a, b));
}
int gcd(int a, int b) {
if (b > a) {
a = a + b;
b = a - b;
a = a - b;
}
if (a != 0 && b != 0)
return gcd(b, a % b);
return a;
}
}
I think so this code might help you. :-)
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.