1 public class Main{ 2 3 public static void main(String []args) { 4 5 int n = 5; 6 System.out.println("Rozwiazanie metoda rekurencyjna: "+ 7 Rekurencyjnie(n)); 8 9 System.out.println("Rozwiazanie metoda iteracyjna: "+ 10 Iteracyjnie(n)); 11 } 12 13 public static int Iteracyjnie(int n) { 14 int a = 0; 15 int b = 1; 16 int c; 17 if (n == 0) { 18 return a; 19 } 20 21 for (int i = 2; i <= n; i++) { 22 c = a * b + 3; 23 a = b; 24 b = c; 25 } 26 return b; 27 } 28 29 public static int Rekurencyjnie(int n) { 30 if (n == 0) { 31 return 0; 32 } else if (n == 1) { 33 return 1; 34 }else 35 return Rekurencyjnie(n-1) * Rekurencyjnie(n-2) + 3; 36 } 37 }