Skip to content

Commit b7c97e1

Browse files
committed
java algorithms
1 parent 34890f0 commit b7c97e1

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

algorithms/Fibonachi.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package algorithms;
2+
3+
public class Fibonachi {
4+
5+
public static void callback_fib(int indx, int val) {
6+
System.out.print(val + " ");
7+
}
8+
9+
public static void iterat_fib(int indx) {
10+
int r = 0;
11+
int r_1 = 0;
12+
int r_2 = 0;
13+
14+
if(indx >= 0) callback_fib(indx, 0);//0
15+
if(indx > 0) callback_fib(indx, 1);//1
16+
17+
if(indx > 1) r_1 = 1;
18+
19+
for(int i = 2; i < indx; i++) {
20+
r = r_1 + r_2;
21+
22+
callback_fib(indx, r);
23+
24+
r_2 = r_1;
25+
r_1 = r;
26+
}
27+
} //iterat_fib
28+
29+
public static int recur_fib(int indx) {
30+
if(indx < 1) return 0;
31+
if(indx < 2) return 1;
32+
33+
return recur_fib(indx - 1) + recur_fib(indx - 2);
34+
} //recur_fib
35+
36+
public static void main(String[] args) {
37+
for(int i = 0; i < 20; i++) {
38+
System.out.print(recur_fib(i) + " ");
39+
}
40+
System.out.println(" ");
41+
iterat_fib(20);
42+
} //main
43+
} //Fibonachi

algorithms/PrimeNumbers.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package algorithms;
2+
3+
public class PrimeNumbers {
4+
5+
public static void print(int cnt) {
6+
int cur_cnt = 0;
7+
while(cur_cnt <= cnt) {
8+
//l
9+
}
10+
} //print
11+
12+
public static void main(String[] args) {
13+
print(20);
14+
} //main
15+
16+
} //PrimeNumbers

0 commit comments

Comments
 (0)