diff options
Diffstat (limited to 'examples/src/main/scala/LocalPi.scala')
-rw-r--r-- | examples/src/main/scala/LocalPi.scala | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/examples/src/main/scala/LocalPi.scala b/examples/src/main/scala/LocalPi.scala new file mode 100644 index 0000000000..c61b3e53d4 --- /dev/null +++ b/examples/src/main/scala/LocalPi.scala @@ -0,0 +1,15 @@ +import scala.math.random +import spark._ +import SparkContext._ + +object LocalPi { + def main(args: Array[String]) { + var count = 0 + for (i <- 1 to 100000) { + val x = random * 2 - 1 + val y = random * 2 - 1 + if (x*x + y*y < 1) count += 1 + } + println("Pi is roughly " + 4 * count / 100000.0) + } +} |