val max = if(a>b){
println("a : $a")
a
} else {
println("b : $b")
b
}
print("Enter the score : ")
val score = readLine()!!.toDouble()
var grade: Char = 'F'
if(score >= 90.0){
grade = 'A'
}
else if(score in 80.0..89.9){ // 범위 연산자 사용
grade = 'B'
}
else if( score >= 70){
grade = 'C'
}
val score = readLine()!!.toDouble()
var grade: Char = 'F'
when(score){
in 90.0..100.0 -> grade = 'A'
in 80.0..89.0 -> grade = 'B'
in 70.0..79.0 -> grade = 'C'
}
println("score : $score, grade : $grade")
when(x){
0,1 -> print("x == 0 or x == 1")
parseInt(s) -> print("일치함!")
}
when(str){
is String -> "문자열입니다."
else -> false
}
for (i in 5 downTo 1) print(i)
for (i in 5..1) print(i) // 이렇게 사용하는거 아님
for (i in 1..5 step 2) print(i)
for(i in 5 downTo 1 step 2) print(i) // 5 3 1 출력
inline fun inlineLambda(a: Int, b:Int, out: (Int, Int) -> Unit) {
out(a,b)
}
fun retFunc() {
println("Start of Func")
inlineLambda(12,3) lit@{
a,b -> val result = a+b
if(result > 10) return@lit // 라벨 사용안하고 return시 retFunc()을 빠져나옴
println()
}
println("end of Func")
}
inline fun inlineLambda(a: Int, b:Int, out: (Int, Int) -> Unit) {
out(a,b)
}
fun retFunc() {
println("Start of Func")
inlineLambda(12,3) {
a,b -> val result = a+b
if(result > 10) return@inlineLambda
println()
}
println("end of Func")
}
inline fun inlineLambda(a: Int, b:Int, out: (Int, Int) -> Unit) {
out(a,b)
}
fun retFunc() {
println("Start of Func")
inlineLambda(12,3,fun (a,b){
val result = a+b
if(result > 10) return
println()
}
println("end of Func")
}
부스트코스 코틀린강좌를 참고하였습니다.