Java Programming

LCM

Java example for lowest common multiple

9/2/2021
0 views
lcm.javaJava
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
LCMLowest Common MultipleJava Tutorial

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com