标签:
1. 在Scala REPL 中键入3.,然后按Tab键。有哪些方法可以被应用?scala>
3
.
%
* - > >> ^ isInstanceOf toChar toFloat toLong toString unary
_
- |
& + / >
=
>>> asInstanceOf toByte toDouble toInt toShort unary
_
+ unary
_
~
scala> import scala.math. _ import scala.math. _ scala> sqrt( 3 ) res 1 : Double = 1.7320508075688772 scala> res 1 * res 1 res 2 : Double = 2.9999999999999996 scala> 3 - res 2 res 3 : Double = 4.440892098500626 E- 16 |
scala> res
3
=
0
<console>
:
16
:
error
:
reassignment to
val
res
3
=
0
^
scala> "crazy" * 3 res 4 : String = crazycrazycrazy
- 在过滤框中输入 String - 选择 StringOps - 找到 * 方法,文档中的说明如下: def *(n: Int): String Return the current string concatenated n times.
|
scala> import scala.util.Random import scala.util.Random scala> import scala.math.BigInt. _ import scala.math.BigInt. _ scala> probablePrime( 100 ,Random) res 12 : scala.math.BigInt = 1220680273650327122886980473381 |
scala> probablePrime(
100
,Random)
res
12
:
scala.math.BigInt
=
1220680273650327122886980473381
scala> probablePrime(
100
,Random).toString(
36
)
res
13
:
String
=
2
f
1
yebpp
8
l
5
ft
8
y
2
afh
7
scala>
val
str
=
"Hello"
str
:
String
=
Hello
scala> str(
0
)
res
14
:
Char
=
H
scala> str.head
res
16
:
Char
=
H
scala> str.last
res
17
:
Char
=
o
标签:
原文地址:http://www.cnblogs.com/chenjo/p/4436580.html