GitHub Viewer
package misc;
import java.util.Scanner;
public class LCM_GCD {
public static void lcm(int n1, int n2) {
int max, step, lcm = 0;
lcm = (n1 > n2) ? (max = step = n1) : (max = step = n2);
while (n1 != 0) {
if (max % n1 == 0 && max % n2 == 0) {
lcm = max;
break;
}
max += step;
}
System.out.println("LCM of given number: " + lcm);
}
public static void gcd(int n1, int n2) {
int i, hcf = 0;
for (i = 1; i