view algs4/1.1.20/LnFact.java @ 0:17ee997bf124

Initial commit
author Eris Caffee <discordia@eldalin.com>
date Sat, 16 May 2015 12:02:55 -0500
parents
children
line source
1 public class LnFact {
2 public static double ln_fact ( int n ) {
3 if ( n < 1 )
4 return -1;
5 if ( n == 1 )
6 return 0;
7 return Math.log( n ) + ln_fact( n - 1 );
8 }
10 // public static double fact ( int n ) {
11 // if ( n < 1 )
12 // return 0;
13 // if ( n == 1 )
14 // return 1;
15 // return n * fact( n - 1 );
16 // }
18 public static void main( String[] args ) {
19 while ( ! StdIn.isEmpty() ) {
20 int n = StdIn.readInt();
21 StdOut.println( ln_fact( n ) );
22 // StdOut.println( Math.log( fact( n ) ) );
23 }
24 }
25 }