LCM

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

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!