Format code
This commit is contained in:
parent
790b07679c
commit
c9a7300269
1 changed files with 22 additions and 21 deletions
39
Fibo.java
39
Fibo.java
|
@ -1,21 +1,22 @@
|
||||||
// Fibonacci number generator in Java using recursion
|
// Fibonacci number generator in Java using recursion
|
||||||
public class Fibo
|
public class Fibo {
|
||||||
{
|
|
||||||
static final int COUNT = 40;
|
|
||||||
|
|
||||||
private static long fibo(int i){
|
static final int COUNT = 40;
|
||||||
if (i < 3)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return fibo(i-1) + fibo(i-2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
private static long fibo(int i) {
|
||||||
System.out.println("Lasketaan fibo: " + COUNT);
|
if (i < 3)
|
||||||
long before = System.currentTimeMillis();
|
return 1;
|
||||||
for (int i=1; i <= COUNT; i++)
|
else
|
||||||
System.out.println("Fibo: " + i + " = " + fibo(i));
|
return fibo(i-1) + fibo(i-2);
|
||||||
long after = System.currentTimeMillis();
|
}
|
||||||
System.out.println("Laskenta kesti: " + (after - before) + " ms");
|
|
||||||
}
|
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