2015年6月22日月曜日

開発環境

Learning Scala: Practical Functional Programming for the JVM (Jason Swartz (著)、O'Reilly Media)のPart Ⅰ. (Core Scala)、Chapter 2.(Working with Data: Literals, Values, Variables, and Types)、Exercises 3, 4, 5, 6.(No. 693)を解いてみる。

その他参考書籍

Exercises 3, 4, 5, 6.(No. 693)

入出力結果(Terminal, REPL(Read, Eval, Print, Loop))

$ scala-2.11 
Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_25).
Type in expressions to have them evaluated.
Type :help for more information.

scala> val a = 2.7255
a: Double = 2.7255

scala> f"You owe $$$a.2f."
res0: String = You owe $2.7255.2f.

scala> val flag = false
flag: Boolean = false

scala> val result = (flag == false)
result: Boolean = true

scala> val result1 = true
result1: Boolean = true

scala> val n = 128
n: Int = 128

scala> n.toChar
res1: Char = €

scala> n.toString
res2: String = 128

scala> val d = n.toDouble
d: Double = 128.0

scala> d.toInt
res3: Int = 128

scala> val s = "Frank, 123 Main, 925-555-1943,95122"
s: String = Frank, 123 Main, 925-555-1943,95122

scala> val pattern = """.*(\d{3})-(\d{3})-(\d{4}).*""".r
pattern: scala.util.matching.Regex = .*(\d{3})-(\d{3})-(\d{4}).*

scala> val pattern(n1,n2,n3) = s
n1: String = 925
n2: String = 555
n3: String = 1943

scala> :q
$

0 コメント:

コメントを投稿

Comments on Google+: