Browse Source

Format code

master
Nyymix 2 months ago
parent
commit
c9a7300269
  1. 43
      Fibo.java

43
Fibo.java

@ -1,21 +1,22 @@
// Fibonacci number generator in Java using recursion
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");
}
}
// Fibonacci number generator in Java using recursion
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…
Cancel
Save