Skip to content

Commit cc6af5f

Browse files
authored
create main function GCD
output 4 main
1 parent 3bd769d commit cc6af5f

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Others/GCD.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
public class GCD{
55

6-
public static int gcd(int a, int b) {
6+
public static int gcd(int a, int b) {
77

88
int r = a % b;
99
while (r != 0) {
@@ -12,13 +12,16 @@ public static int gcd(int a, int b) {
1212
}
1313
return b;
1414
}
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+
}
1622

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+
}
2427
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy