Kotlin 代码格式化工具
专业级的 Kotlin 代码格式化与美化
data class Person(val name: String, val age: Int)
fun calculateTotal(items: List<Item>): Double {
var total = 0.0
for (item in items) {
total += item.price * item.quantity
}
return if (total > 1000) {
total * 0.9 // 10% discount
} else {
total
}
}
fun main() {
val items = listOf(
Item("Laptop", 1200.0, 1),
Item("Mouse", 25.0, 2),
Item("Keyboard", 60.0, 1)
)
println("Total amount: ${calculateTotal(items)}")
}