import java.math.BigInteger; /** * Calculate the first N fibonacci numbers, but do it really slowly * @author gtowell * created: Oct 2022 */ public class BadFibb { /** * Return the Nth fibonacci number. * @param n the fibb number to calculate * @return the Nth fibb number */ public long fibonacci(int n) { // check that n is valid if (n <= 0) return 0; if (n < 3) return 1; return fibonacci(n - 1) + fibonacci(n - 2); } public static void main(String[] args) { BadFibb fib = new BadFibb(); for (int i = 0; i < 50; i++) { // get the time required (in milliseconds) long st = System.nanoTime(); System.out.println( "Fibb number " + i + " = " + fib.fibonacci(i) + " time: " + (System.nanoTime() - st) / 1000000); } } }