nikolas_serafini

Fatorial - recursive

Oct 5th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.35 KB | None | 0 0
  1. class neoFatorial {
  2.     double element;
  3.     double calcFatorial(double var) {
  4.         if(var == 0)
  5.             return 1;
  6.         else
  7.             return var * calcFatorial(var - 1);
  8.     }
  9.  
  10.     public static void main(String[] args) {
  11.         neoFatorial fatorial = new neoFatorial();
  12.        
  13.         fatorial.element = 5;
  14.         System.out.println("Fatorial : " + fatorial.calcFatorial(fatorial.element));
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment