Created
November 28, 2015 07:51
-
-
Save jukbot/5b93fa9bee58fd754e98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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