Guest User

Untitled

a guest
Jan 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. package test;
  2.  
  3. import java.math.BigInteger;
  4.  
  5. public class Test {
  6.    
  7.     public static void main(String[] args) {
  8.  
  9.         new Test().run();
  10.     }
  11.     void run(){
  12.         System.out.println("normal factorial: " +fact(50));
  13.         System.out.println("tail factorial: " +fact_tail(1, 50));
  14.  
  15.  
  16.    
  17.     public long fact_tail(long product, long target ){
  18.         if (target == 1) return product;
  19.         return fact_tail(product* target, target - 1);
  20.     }
  21.    
  22.     public long fact(int n){
  23. if (n < 1) return n;
  24. return n* fact(n-1);
  25.     }
  26.    
  27.          
  28. }
Add Comment
Please, Sign In to add comment