File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11//Oskar Enmalm 3/10/17
22//This is Euclid's algorithm which is used to find the greatest common denominator
3+ //Overide function name gcd
34
45public class GCD {
56
6- public static int gcd (int a , int b ) {
7-
8- int r = a % b ;
9- while (r != 0 ) {
10- b = r ;
11- r = b % r ;
7+ public static int gcd (int num1 , int num2 ) {
8+
9+ int gcdValue = num1 % num2 ;
10+ while (gcdValue != 0 ) {
11+ num2 = gcdValue ;
12+ gcdValue = num2 % gcdValue ;
1213 }
13- return b ;
14+ return num2 ;
1415 }
1516 public static int gcd (int [] number ) {
1617 int result = number [0 ];
1718 for (int i = 1 ; i < number .length ; i ++)
19+ //call gcd function (input two value)
1820 result = gcd (result , number [i ]);
1921
2022 return result ;
2123 }
2224
2325 public static void main (String [] args ) {
2426 int [] myIntArray = {4 ,16 ,32 };
27+ //call gcd function (input array)
2528 System .out .println (gcd (myIntArray ));
2629 }
2730}
You can’t perform that action at this time.
0 commit comments