Skip to content

Instantly share code, notes, and snippets.

@jukbot
Created November 28, 2015 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jukbot/5b93fa9bee58fd754e98 to your computer and use it in GitHub Desktop.
Save jukbot/5b93fa9bee58fd754e98 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class GCD {
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Give me 2 numbers for GCD question: ");
int x = input.nextInt();
int y = input.nextInt();
int z = gcd1(x,y);
System.out.println("GCD of " + x + " and " + y + " are " + z);
}
public static int recursiveGCD_ajarn(int a, int b) {
if(b >a) {
int temp = b; b = a; a = temp;
}
// base case
if(b == 0) return a;
else return recursiveGCD_ajarn(b, a%b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment