create main function GCD
output 4 main
This commit is contained in:
parent
3bd769d2ae
commit
cc6af5f59e
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
public class GCD{
|
public class GCD{
|
||||||
|
|
||||||
public static int gcd(int a, int b) {
|
public static int gcd(int a, int b) {
|
||||||
|
|
||||||
int r = a % b;
|
int r = a % b;
|
||||||
while (r != 0) {
|
while (r != 0) {
|
||||||
@ -12,13 +12,16 @@ public static int gcd(int a, int b) {
|
|||||||
}
|
}
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
public static int gcd(int[] number) {
|
||||||
|
int result = number[0];
|
||||||
|
for(int i = 1; i < number.length; i++)
|
||||||
|
result = gcd(result, number[i]);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//Increase the number of calculations.
|
public static void main(String[] args) {
|
||||||
//Use functoin from above as recursive.
|
int[] myIntArray = {4,16,32};
|
||||||
public static int gcd(int[] number) {
|
System.out.println(gcd(myIntArray));
|
||||||
int result = number[0];
|
}
|
||||||
for(int i = 1; i < number.length; i++)
|
|
||||||
result = gcd(result, number[i]);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user