forked from srinathr91/TestJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnswerGCD.java
More file actions
51 lines (40 loc) · 645 Bytes
/
AnswerGCD.java
File metadata and controls
51 lines (40 loc) · 645 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.Arrays;
public class AnswerGCD {
public static int gcd(int a,int b){
if(a<b){
int temp=a;
a=b;
b=temp;
}
if(b==0){
return a;
}
return gcd(b,a%b);
}
public static int gcd1(int[] arr){
if(arr.length==1){
return arr[0];
}
int ans=arr[0];
for(int i= 1;i<arr.length;i++){
if(ans<arr[i]){
int temp=ans;
ans=arr[i];
ans=temp;
}
int b= arr[i];
while(b!=0){
int r=ans%b;
ans=b;
b=r;
}
}
return ans;
}
public static void main(String[] args){
int a=61;
int b=18;
int[] arr={70};
System.out.println(gcd1(arr));
}
}