package com.ysk
import com.sun.crypto.provider.AESCipher
import com.sun.crypto.provider.AESCipher.AES128_CBC_NoPadding
/**
* Created by Y.S.K on 2017/8/31 in spark02.
*/
object Greeting extends App {
println(
"welcome ysk")
val v =
1
println(v)
println(
"hello," +
"ysk" +
"!")
val x =
10
var y =
20
y += x
print(y)
val a: Byte =
10
val b: Short =
20
val c: Int =
40
val d: Long =
40
val e: Float =
50
val f: Double =
60.98755
val m =
true
val n =
false
val q =
'x'
val u: Unit = ()
val p = ()
def foo() =
throw new Exception(
"error occurred")
val name =
"Y.S.K"
s
"my name is ${name}"
def hello(name: String): String = {
s
"hello,${name}"
}
hello(
"Y.S.K")
def hello1(name: String) = {
s
"hello,${name}"
}
hello1(
"Y.S.K")
def add(x: Int, y: Int) = {
x + y
}
add(
1,
2)
val l = List(
"ysk",
"ysk2",
"ysk3")
for {
s <- l
} println(s)
for {
s <- l
if (s.length >
3)
} println(s)
val result_for =
for {
s <- l
s1 = s.toUpperCase()
if (s1 !=
"")
}
yield (s1)
val result_try =
try {
Integer.parseInt(
"dog")
}
catch {
case _: Throwable =>
0
}
finally {
println(
"always be printed")
}
val code =
1
val result_match = code
match {
case 1 =>
"one"
case 2 =>
"two"
case _ =>
"others"
}
def test1(x: Int, y: Int) = {
x * x
}
def test2(x: => Int, y: => Int) = {
x * x
}
test1(
3 +
4,
8)
test2(
3 +
4,
8)
test1(
7,
2 *
4)
test2(
7,
2 *
4)
def bar(x: Int, y: => Int) =
1
def loop(): Int = loop
bar(
1, loop)
def factorial(n: Int): Int =
if (n <=
0)
1
else n * factorial(n -
1)
@annotation.tailrec
def factorial2(n: Int, m: Int): Int =
if (n <=
0)
1
else factorial2(n -
1, m * n)
var greeting = (name: String) => {
"hello, " + name
}
greeting(Y.S.K)
def curriedAdd(a: Int)(b: Int) = a + b
curriedAdd(
2)(
2)
val addOne = curriedAdd(
1) _
addOne(
2)
}