Code · 1 file
Sample Kotlin File
Kotlin is a concise JVM language and the preferred language for Android. The Kotlin sample is a small program — a customer record, a VIP check and a formatted total — that is the same in every language we offer, so you can compare them side by side.
Kotlin · 541 B
Sample Kotlin file
An idiomatic Kotlin example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.
CC0 · free for any use · Verified by an independent tool · Report a problem
// Sample Kotlin program — samplefiles.com
data class Customer(val id: Int, val name: String, val balance: Double) {
val isVip get() = balance >= 10_000
}
fun totalBalance(customers: List<Customer>) = customers.sumOf { it.balance }
fun main() {
val customers = listOf(Customer(1, "Ada", 12_500.0), Customer(2, "Grace", 830.5), Customer(3, "Linus", 10_000.0))
customers.forEach { println("%-6s %10.2f %s".format(it.name, it.balance, if (it.isVip) "VIP" else "")) }
println("Total: %.2f".format(totalBalance(customers)))
}File details
Download from the command line
curl -L -o sample.kt https://files.samplefiles.com/code/kt/sample.ktwget https://files.samplefiles.com/code/kt/sample.kthttps://files.samplefiles.com/code/kt/sample.ktprintf '%s %s\n' 69f01daf27d696568caaac215448e16650ce86e81c05fb7c1cbf24b3f71230f4 sample.kt | shasum -a 256 -cOr check the download in your browser with the checksum calculator.