Completed Coursera: Kotlin for developers course
This commit is contained in:
24
src/In.kt
Normal file
24
src/In.kt
Normal file
@ -0,0 +1,24 @@
|
||||
import java.time.Instant
|
||||
|
||||
fun main() {
|
||||
// Check if a is in abc
|
||||
println('a' in "abc")
|
||||
// Check if a is not in abc
|
||||
println('a' !in "abc")
|
||||
// Check if now is within the bounds, using comparable under the hood
|
||||
println(Instant.now() in Instant.MIN..Instant.MAX)
|
||||
}
|
||||
|
||||
/// Playground
|
||||
fun isValidIdentifier(s: String): Boolean {
|
||||
fun isValidCharacter(ch: Char): Boolean = ch == '_' || ch.isLetterOrDigit()
|
||||
if (s.isEmpty() || s[0].isDigit()) {
|
||||
return false
|
||||
}
|
||||
for (ch in s) {
|
||||
if (!isValidCharacter(ch)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user