-
Notifications
You must be signed in to change notification settings - Fork 0
/
practise.scala
61 lines (51 loc) · 1.21 KB
/
practise.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
object SayHello{
def sayhello(msg: String ) = {
println(msg);
}
}
/*以下helloworld单例对象是helloworld类的 Companion Object*/
class helloworld(msg: String){
def sayhello() = {
val message = helloworld.say(msg)
println(message)
}
}
object helloworld {
def say(msg:String ) = msg + ", hello world"
}
object Say {
def main(args: Array[String]) {
var hw:helloworld = new helloworld("Hi,my name is lming_08")
hw.sayhello();
val pair = (99, "abc")
println(pair._1)
println(pair._2)
SayHello.sayhello("This is Scala Programming Language")
var arr:Array[String] = new Array[String](3)
arrLoop(arr)
arrLoop2(arr)
arrLoop3(arr)
}
def getStr(msg:String ) = msg + ", hello"
def arrLoop(arr:Array[String]) = {
arr(0) = "abc"
arr(1) = "123"
arr(2) = "ABC"
for(elem <- arr)
println( elem + ", hello")
}
def arrLoop2(arr:Array[String]) = {
arr(0) = "+abc"
arr(1) = "+123"
arr(2) = "+ABC"
arr.foreach(elem => println(elem))
}
def arrLoop3(arr:Array[String]) = {
arr(0) = "-abc"
arr(1) = "-123"
arr(2) = "-ABC"
for(i <- 0 to arr.length - 1){
println(arr(i))
}
}
}