Mercurial > op > Looping
annotate Looping.scala @ 9:30b521e712f5 >>178
JavaScript (xhtml) のソースコードを追加。
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Wed, 23 Feb 2011 01:17:31 +0900 |
parents | 69b8c75e9c24 |
children |
rev | line source |
---|---|
7
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
1 class LClass { |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
2 def calc(n:Int): Int = { |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
3 var n1 = n0 + (1 - 2*(n%2)) |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
4 n0 = n; |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
5 return n1; |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
6 } |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
7 private var n0:Int = 0 |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
8 } |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
9 |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
10 object Looping { |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
11 def main(args :Array[String]):Unit = { |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
12 var o = new LClass() |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
13 var n = 1 |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
14 var t1 = System.currentTimeMillis() |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
15 for(c <- 0 to Integer.MAX_VALUE - 1){ |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
16 n = o.calc(n); |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
17 } |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
18 var t2 = System.currentTimeMillis() |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
19 println(n + "\nScala:\t" + (t2 - t1)) |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
20 } |
69b8c75e9c24
Scalaのソースコードを追加。
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
21 } |