Add Java version
This commit is contained in:
parent
0e78f2ac8d
commit
6fd882f53f
1 changed files with 20 additions and 0 deletions
20
Fibo.java
Normal file
20
Fibo.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
public class Fibo
|
||||
{
|
||||
static final int count = 40;
|
||||
|
||||
private static long fibo(int i){
|
||||
if (i < 3)
|
||||
return 1;
|
||||
else
|
||||
return fibo(i-1) + fibo(i-2);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Lasketaan fibo: " + count);
|
||||
long before = System.currentTimeMillis();
|
||||
for (int i=1; i <= count; i++)
|
||||
System.out.println("Fibo: " + i + " = " + fibo(i));
|
||||
long after = System.currentTimeMillis();
|
||||
System.out.println("Laskenta kesti: " + (after - before) + " ms");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue