Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/lsp4you/public_html/connect.php on line 2 LSP4YOU - Learner's Support Publications

Pi Value Calculation



object CollectionsDay2 {
  println("Welcome to the Scala worksheet")       //> Welcome to the Scala worksheet
  

  val dx = 0.0001                                 //> dx  : Double = 1.0E-4
 // val x = Range.Double(0.0,1.0,dx)
//  val y = x.map(v => 1.00/(1.00 + v * v))
//  val pi = y.reduce(_+_)*dx *4
  
  val pi = Range.Double(0.0,1.0,dx)
  					.map(v => 1.00/(1.00 + v * v))
  					.reduce(_+_)*dx *4
                                                  //> pi  : Double = 3.14169265192314
}