|
Scala example source code file (harmonic.scala)
The Scala harmonic.scala source code/* ------------------------------------------------------------------ */ /* The Great Computer Language Shootout */ /* http://shootout.alioth.debian.org/ */ /* */ /* Contributed by Anthony Borla */ /* ------------------------------------------------------------------ */ import java.text.DecimalFormat; import java.text.FieldPosition; object harmonic { def main(args: Array[String]) { var n = Integer.parseInt(args(0)); var value = harmonic(n, 0.0); val formatter = new DecimalFormat("#.000000000"); var formattedValue = formatter.format(value, new StringBuffer(), new FieldPosition(0)); System.out.println(formattedValue); } final def harmonic(n: Int, a: Double): Double = if (n == 0) a else harmonic(n - 1, a + 1.0 / n); } Other Scala examples (source code examples)Here is a short list of links related to this Scala harmonic.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.