view Looping.scala @ 12:dab1e83799e4 >>178 tip

R版のソースコードを追加。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Sat, 04 Feb 2012 04:10:01 +0900
parents 69b8c75e9c24
children
line wrap: on
line source

class LClass {
	def calc(n:Int): Int = {
		var n1 = n0 + (1 - 2*(n%2))
		n0 = n;
		return n1;
	}
	private var n0:Int = 0
}

object Looping {
	def main(args :Array[String]):Unit = {
		var o = new LClass()
		var n = 1
		var t1 = System.currentTimeMillis()
		for(c <- 0 to Integer.MAX_VALUE - 1){
			n = o.calc(n);
		}
		var t2 = System.currentTimeMillis()
		println(n + "\nScala:\t" + (t2 - t1))
	}
}