mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-09 08:31:29 +00:00
25 lines
433 B
Kotlin
25 lines
433 B
Kotlin
fun StringBuilder.takeFirst(): Char {
|
|
if (this.length() == 0) return 0.toChar()
|
|
val c = this.charAt(0)
|
|
this.deleteCharAt(0)
|
|
return c
|
|
}
|
|
|
|
fun foo(expr: StringBuilder): Int {
|
|
val c = expr.takeFirst()
|
|
when(c) {
|
|
0.toChar() -> throw Exception("zero")
|
|
else -> throw Exception("nonzero" + c)
|
|
}
|
|
}
|
|
|
|
fun box(): String {
|
|
try {
|
|
foo(StringBuilder())
|
|
return "Fail"
|
|
}
|
|
catch (e: Exception) {
|
|
return "OK"
|
|
}
|
|
}
|