File: harmonic.java

package info (click to toggle)
groovy2 2.2.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 23,916 kB
  • sloc: java: 136,570; xml: 948; sh: 486; makefile: 67; ansic: 64
file content (23 lines) | stat: -rw-r--r-- 577 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* The Great Computer Language Shootout
   http://shootout.alioth.debian.org/
 
   contributed by Paul Lofte
*/

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class harmonic {

    static final NumberFormat formatter = new DecimalFormat("#.000000000");
    
    public static void main(String[] args) {
        int n = 10000000;
        if (args.length > 0) n = Integer.parseInt(args[0]);

        double partialSum = 0.0;
        for (int i=1; i<=n; i++) partialSum += 1.0/i;
        
        System.out.println(formatter.format(partialSum));
    }
}