for 와 in, range 데이터 형식 Kotlin

i in 1..10
i >= 1 && i <= 10

for (i in 1..1000) {
print(i)
}
for (i in 100 downTo 1 step 2) {
print(i)
}
for (i in 0 until 10) { // 0 ~ 9

}
for (i in 0..10 - 1) {

}

val binaryReps = TreeMap<Char, String>()
for (c in 'A'..'F') {
val binary = Integer.toBinaryString(c.toInt())
binaryReps[c] = binary
}
for ((letter, binary) in binaryReps) {
println("$letter = $binary")
}


val list = arrayListOf("10", "11", "1001")
for ((index, element) in list.withIndex()) {
println("$index: $element")
}



fun isLetter(c: Char) = c in 'a'..'z' || c in 'A'..'Z'
fun isNotDigit(c: Char) = c !in '0'..'9'
fun recognize(c: Char) =
when (c) {
in '0'..'9' -> "Digit"
in 'a'..'z', in 'A'..'Z' -> "Letter"
else -> "I don't know"
}

fun between(s: String) = "Kotlin" in "Java".."Scala" // String Compare 연산

덧글

댓글 입력 영역