Java Programming

GCD

Java example for find the greatest common divisor of two number

9/1/2021
0 views
gcd.javaJava
import java.io.*;

class divisor {

	/* Recursive method */
	void common_divisor(int x, int y) {
		if(y == 0)
			System.out.println("GCD value: "+x);
		else

			/* Call the common_divisor method inside in it */
			common_divisor(y, x % y);
	}
}

class gcd {
	public static void main(String args[ ]) {
		divisor d = new divisor();
		d.common_divisor(Integer.parseInt(args[0]),Integer.parseInt(args[1]));
	}
}



/* Output */
java gcd 10 5
GCD value: 5
Greatest Common DivisorGCDJava 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