document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. public class Ricorsiva
  2. {
  3.     public static double fattoriale(double n)
  4.     {
  5.         //5! = 5*4*3*2*1
  6.         if(n==1)
  7.         {
  8.             return 1;
  9.         }
  10.         else
  11.         {
  12.             return n * fattoriale(n-1);
  13.         }
  14.     }
  15.    
  16.     public static int fibonacci(int n)
  17.     {
  18.         //0,1,1,2,3,5,8,13,21,34
  19.         if(n==1)
  20.         {
  21.             return 0;
  22.         }
  23.        
  24.         if(n==2)
  25.         {
  26.             return 1;
  27.         }
  28.        
  29.         return fibonacci(n-1) + fibonacci(n-2);
  30.     }
  31. }
');