package calcpi

object pi {

    def estimate_pi(n: Int): Double = {
        var psum = 0.0d;
        val step = 1d/n;
        
        for (i <-  1 to n) {
            var x = (i - 0.5d) * step
            psum = psum + 4d/(1d + (x * x))
        } 
        
        psum * step
        
    }

    def main(args: Array[String]) {
        var n = 500000000

        if (args.length == 1) {
            n = Integer.parseInt(args(0))
        }

        println("Calculating PI using:")
        println("  " + n + " slices")
        println("  1 processes")

        val start = System.currentTimeMillis();

        
        var mypi = estimate_pi(n)
        
        val stop = System.currentTimeMillis();
        val difference = stop - start;
        val time = difference/1000.0d;
        
        println("Obtained value of PI: " + mypi);
        println("Time taken: " + time + " seconds");
  }
}

package calcpi

object pi extends App {
    var n = 500000000

    if (args.length == 1) {
        n = Integer.parseInt(args(0))
    }

    println("Calculating PI using:")
    println("  " + n + " slices")
    println("  1 processes")

    val start = System.currentTimeMillis();

    var psum = 0.0d;
    val step = 1d/n;
        
    for (i <-  1 to n) {
        var x = (i - 0.5d) * step
        psum = psum + 4d/(1d + (x * x))
    } 
        
    var mypi = psum * step;
        
    val stop = System.currentTimeMillis();
    val difference = stop - start;
    val time = difference/1000.0d;
        
    println("Obtained value of PI: " + mypi);
    println("Time taken: " + time + " seconds");
}

--- 
+++ 
@@ -1,32 +1,41 @@
 package calcpi
 
-object pi extends App {
-    var n = 500000000
+object pi {
 
-    if (args.length == 1) {
-        n = Integer.parseInt(args(0))
+    def estimate_pi(n: Int): Double = {
+        var psum = 0.0d;
+        val step = 1d/n;
+        
+        for (i <-  1 to n) {
+            var x = (i - 0.5d) * step
+            psum = psum + 4d/(1d + (x * x))
+        } 
+        
+        psum * step
+        
     }
 
-    println("Calculating PI using:")
-    println("  " + n + " slices")
-    println("  1 processes")
+    def main(args: Array[String]) {
+        var n = 500000000
 
-    val start = System.currentTimeMillis();
+        if (args.length == 1) {
+            n = Integer.parseInt(args(0))
+        }
 
-    var psum = 0.0d;
-    val step = 1d/n;
+        println("Calculating PI using:")
+        println("  " + n + " slices")
+        println("  1 processes")
+
+        val start = System.currentTimeMillis();
+
         
-    for (i <-  1 to n) {
-        var x = (i - 0.5d) * step
-        psum = psum + 4d/(1d + (x * x))
-    } 
+        var mypi = estimate_pi(n)
         
-    var mypi = psum * step;
+        val stop = System.currentTimeMillis();
+        val difference = stop - start;
+        val time = difference/1000.0d;
         
-    val stop = System.currentTimeMillis();
-    val difference = stop - start;
-    val time = difference/1000.0d;
-        
-    println("Obtained value of PI: " + mypi);
-    println("Time taken: " + time + " seconds");
+        println("Obtained value of PI: " + mypi);
+        println("Time taken: " + time + " seconds");
+  }
 }
Rework to make more sense.
