Interactive Interpretation

Question

Using Scala’s Interactive Interpreter

Solution

"Hello, World"
8 + 5
8 * 5 + 2
0.5 * 42
"hello, " + 42
"Hello, World".toLowerCase
42.toString
"Hello, World".toUpperCase
val answer = 8 * 5 + 2
0.5 * answer
// answer = 0
// error: reassignment to val
var count = 0
count = 1
val greeting: String = null
val greeting2: Any = "Hello"
1.to(10)
val xmax, ymax = 100
1.toString()

val a = 10
val b = 20
a.+(b)

1 to 10

val x: BigInt = 123456790
x * x * x
import scala.math._
sqrt(2)
pow(2, 4)
min(3, Pi)
"Hello".distinct
"hello"(4)
"Hello".apply(4)
BigInt("1234567890")
BigInt.apply("1234567890")
"Harry".patch(1, "ung", 2)

Explanation

res0: String = Hello, World
res1: Int = 13
res2: Int = 42
res3: Double = 21.0
res4: String = hello, 42
res5: String = hello, world
res6: String = 42
res7: String = HELLO, WORLD
answer: Int = 42
res8: Double = 21.0


count: Int = 0
count: Int = 1
greeting: String = null
greeting2: Any = Hello
res9: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
xmax: Int = 100
ymax: Int = 100
res10: String = 1

a: Int = 10
b: Int = 20
res11: Int = 30

res12: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

x: scala.math.BigInt = 123456790
res13: scala.math.BigInt = 1881676417513891481839000
import scala.math._
res14: Double = 1.4142135623730951
res15: Double = 16.0
res16: Double = 3.0
res17: String = Helo
res18: Char = o
res19: Char = o
res20: scala.math.BigInt = 1234567890
res21: scala.math.BigInt = 1234567890
res22: String = Hungry
Comments by Disqus