diff options
author | a.vandijk <anton.van.dijk@live.nl> | 2014-08-15 15:47:12 +0200 |
---|---|---|
committer | a.vandijk <anton.van.dijk@live.nl> | 2014-08-15 15:56:56 +0200 |
commit | d2cf0062822ec364a21afa6550d4d0538857a7fe (patch) | |
tree | 0b7e8d960ed30b2a97204945d15a02f8163fce6c /scala.html.markdown | |
parent | 07b6229ee608ae37283a827112b5eab4c58a5333 (diff) |
[CHANGE] Output examples added to matcher part and string interpolation part.
Diffstat (limited to 'scala.html.markdown')
-rw-r--r-- | scala.html.markdown | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/scala.html.markdown b/scala.html.markdown index 619c8aae..eae39abb 100644 --- a/scala.html.markdown +++ b/scala.html.markdown @@ -332,11 +332,10 @@ val matcher = (value: String) => { }) } -matcher("mrbean@pyahoo.com") -matcher("nope..") -matcher("52917") -matcher("52752-16432-22178-47917") - +matcher("mrbean@pyahoo.com") // => "It was an email: mrbean" +matcher("nope..") // => "No match on 'nope..'" +matcher("52917") // => "No match on '52917'" +matcher("52752-16432-22178-47917") // => "Serial key: 52752, 16432, 22178, 47917" // Strings @@ -359,13 +358,13 @@ println(s"We have $n apples") // Expressions inside interpolated strings are also possible val a = Array(11, 9, 6) -println(s"My second daughter is ${a(0) - a(2)} years old") -println(s"We have double the amount of ${n / 2.0} in apples.") -println(s"Power of 2: ${math.pow(2, 2)}") // Power of 2: 4.0 +println(s"My second daughter is ${a(0) - a(2)} years old") // => "My second daughter is 5 years old" +println(s"We have double the amount of ${n / 2.0} in apples.") // => "We have double the amount of 22.5 in apples." +println(s"Power of 2: ${math.pow(2, 2)}") // => "Power of 2: 4" // Formatting with interpolated strings (note the prefixed f) -println(f"Power of 5: ${math.pow(5, 2)}%1.0f") // Power of 5: 25 -println(f"Square root of 122: ${math.sqrt(122)}%1.4f") // Square root of 122 +println(f"Power of 5: ${math.pow(5, 2)}%1.0f") // "Power of 5: 25" +println(f"Square root of 122: ${math.sqrt(122)}%1.4f") // "Square root of 122" // Ignoring special characters. println(raw"New line feed: \n. Carriage return: \r.") |