File tree 1 file changed +12
-9
lines changed
1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change 3
3
4
4
public class GCD {
5
5
6
- public static int gcd (int a , int b ) {
6
+ public static int gcd (int a , int b ) {
7
7
8
8
int r = a % b ;
9
9
while (r != 0 ) {
@@ -12,13 +12,16 @@ public static int gcd(int a, int b) {
12
12
}
13
13
return b ;
14
14
}
15
- }
15
+ public static int gcd (int [] number ) {
16
+ int result = number [0 ];
17
+ for (int i = 1 ; i < number .length ; i ++)
18
+ result = gcd (result , number [i ]);
19
+
20
+ return result ;
21
+ }
16
22
17
- //Increase the number of calculations.
18
- //Use functoin from above as recursive.
19
- public static int gcd (int [] number ) {
20
- int result = number [0 ];
21
- for (int i = 1 ; i < number .length ; i ++)
22
- result = gcd (result , number [i ]);
23
- return result ;
23
+ public static void main (String [] args ) {
24
+ int [] myIntArray = {4 ,16 ,32 };
25
+ System .out .println (gcd (myIntArray ));
26
+ }
24
27
}
You can’t perform that action at this time.
0 commit comments