Last active
February 19, 2016 02:17
-
-
Save gilrg18/b40f55adee6241eb3f89 to your computer and use it in GitHub Desktop.
WSQ06 TC201 GCD
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
//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