Skip to content

Instantly share code, notes, and snippets.

@gilrg18
Last active February 19, 2016 02:17
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 gilrg18/b40f55adee6241eb3f89 to your computer and use it in GitHub Desktop.
Save gilrg18/b40f55adee6241eb3f89 to your computer and use it in GitHub Desktop.
WSQ06 TC201 GCD
//Greatest Common Divisor by Gilberto Rogel García A01630171
public class GCD {
public int num;
public GCD(int num){
this.num = num;
}
public int greatestCD(int x){
if (this.num == x){
//System.out.println("a"+x);
return x;
}
else{
if(x > this.num){
x = x - this.num;
//System.out.println("b"+x);
return this.greatestCD(x);
}
else{
this.num = this.num - x;
//System.out.println("c"+x);
return this.greatestCD(x);
}
}
}
public static void main(String[] args){
GCD banana1 = new GCD(25);
int z = banana1.greatestCD(10);
System.out.println("Greatest Common Divisor: "+ z);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment