Featured image of post beginning of kotlin

beginning of kotlin

val vs var

kotlinJS
valconst
varlet

a..b

kotlinJS
a..bArray(b-a+1).fill(0).map(i => i + a)

when

kotlin

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
fun main (){
	val luckyNum = 4
	val yourNum = (1..6).random()
	val result = when(yourNum){
		luckyNum -> "You get the lucky num ${luckyNum}"
		1 -> "Sorry, you get 1"
		2 -> "Sorry, you get 2"
		3 -> "Sorry, you get 3"
		4 -> "Sorry, you get 4"
		5 -> "Sorry, you get 5"
		6 -> "Sorry, you get 6"
		else -> "Sorry, you get a number out of 1..6"
	}
	println(result)
}
Licensed under CC BY-NC-SA 4.0
好想養貓阿~~
使用 Hugo 建立
主題 StackJimmy 設計