Get Website Learn Coding Tech Story

Java Programming Examples

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

Learn more about Greatest Common Divisor