Thu Sep 02 2021
LCM
Java Programming1272 views
File Name: lcm.java
import java.io.*;
class divisor {
/* Recursive method */
int common_divisor(int x, int y) {
if(y == 0)
return x;
else
/* Call the common_divisor method inside in it */
return common_divisor(y, x % y);
}
}
class lcm {
public static void main(String args[ ]) {
int a, b, gcd, lcm;
divisor d = new divisor();
a = Integer.parseInt(args[0]);
b = Integer.parseInt(args[1]);
gcd = d.common_divisor(a,b);
lcm = (a * b) / gcd;
System.out.println("Lcm value: "+lcm);
}
}
/* Output */
java lcm 30 20
LCM value: 60
Reference:
Author:Geekboots