forked from kstrauser/python-jvm-interpreter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IntegerTest.java
58 lines (46 loc) · 1.01 KB
/
IntegerTest.java
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
52
53
54
55
56
57
58
package jvmtest;
class IntegerTest {
public static int return0() {
return 0;
}
public static int return1() {
return 1;
}
public static int return5000() {
return 5000;
}
public static int passthrough(int a) {
return a;
}
public static int passthrough_loop(int a) {
int b = 0;
for (int i = 0; i < a; i++) {
b++;
}
return b;
}
public static int doubleNum(int a) {
return a * 2;
}
public static int power(int a) {
return a * a;
}
public static int recursiveFibonacci(int n) {
return (n < 2) ? n : recursiveFibonacci(n - 1)
+ recursiveFibonacci(n - 2);
}
public static int iterativeFibonacci(int n) {
if (n < 2) {
return n;
}
int ans = 0;
int n1 = 0;
int n2 = 1;
for(n--; n > 0; n--) {
ans = n1 + n2;
n1 = n2;
n2 = ans;
}
return ans;
}
}