Wed Sep 01 2021

GCD

File Name: gcd.java

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

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