Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. public static void main(String[] args) {
  2.         System.out.println("цикл   " + factCycle(4));
  3.  
  4.         System.out.println("рекурсия   " + factRecyrsia(4));
  5.     }
  6.  
  7.     public static int factCycle(int n)
  8.     {
  9.         int result = 1;
  10.         for(int i=1;i<=n;i++)
  11.         {
  12.             result *=i;
  13.         }
  14.         return result;
  15.     }
  16.  
  17.     public static int factRecyrsia(int n)
  18.     {
  19.         int result;
  20.  
  21.         if (n == 1)
  22.             return 1;
  23.         result = factRecyrsia(n - 1) * n;
  24.         return result;
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement