-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcd.java
More file actions
36 lines (31 loc) · 929 Bytes
/
gcd.java
File metadata and controls
36 lines (31 loc) · 929 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
package BasicJavaProblems;
public class gcd {
static int GeneralMethod(int a, int b) {
int gcd = 0;
for (int i = 1; i <= a && i <= b; i++) {
if (a % i == 0 && b % i == 0)
gcd = i;
}
return gcd;
}
static int eludienSub(int a, int b) {
if (b == 0)
return a;
else
return eludienSub(b, Math.abs(a - b));
}
static int eludienMod(int a, int b) {
if (b == 0)
return a;
else
return eludienSub(b, (a % b));
}
public static void main(String[] args) {
System.out.println("General Method :");
System.out.println(GeneralMethod(20, 30));
System.out.println("Eudien Algorithm(Subtraction)");
System.out.println(eludienSub(20, 30));
System.out.println("Eudien Algorithm(%)");
System.out.println(eludienMod(20, 30));
}
}