Completed Coursera: Kotlin for developers course

This commit is contained in:
Martin Berg Alstad
2025-07-30 14:34:03 +02:00
commit 80c14c76ba
41 changed files with 608 additions and 0 deletions

24
src/In.kt Normal file
View 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
}