Wed Sep 01 2021
GCD
Java Programming893 views
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
Reference:
Author:Geekboots