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.kt — first linesKotlin
// 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

Size
541 B (541 bytes)
MIME type
text/x-kotlin
SHA-256
69f01daf27d696568caaac215448e16650ce86e81c05fb7c1cbf24b3f71230f4
MD5
2708fe129e32a4be842fdbf9ededa489

Download from the command line

curl -L -o sample.kt https://files.samplefiles.com/code/kt/sample.kt

Or check the download in your browser with the checksum calculator.