Kotlin kotlin.math.max
Choose the larger of the reserved count and the current seating target.
A simple example
kotlin.math.max
- Start with 2 and 5
- Do this Choose the larger value
- Result 5
fun main() {
println(kotlin.math.max(2.0, 5.0))
}
5.0
Syntax
kotlin.math.max(booked, capacity)
Run these examples in Kotlin
Save one example at a time as Lesson.kt. Use Kotlin 2.2 on JDK 21.
kotlinc Lesson.kt -include-runtime -d lesson.jar
java -jar lesson.jarKeep enough seats for a booking
A booking screen receives a requested party size and the current seat inventory. Use the available capacity to decide how many places can actually be assigned.
fun main() {
val booked = 18.0
val capacity = 20.0
System.out.printf(java.util.Locale.ROOT, "%.3f%n", (kotlin.math.max(booked, capacity)).toDouble())
}
20.000
Eighteen bookings and a seating target of twenty require planning for twenty places.
Record the busiest hour at a help desk
A help desk is planning coverage for its busiest period. Compare the recorded hourly loads to identify the peak that the next shift needs to handle.
fun main() {
val baseline = 15.0
val current = 23.0
System.out.printf(java.util.Locale.ROOT, "%.3f%n", (kotlin.math.max(baseline, current)).toDouble())
}
23.000
The current count of 23 exceeds the previous record of 15.
Keep the busiest counter reading
A librarian has recorded a peak of 17 checkouts in an hour. The current hour reaches 21 and the dashboard refreshes its peak.
Taking the greater count updates the peak only when demand rises.
What to watch for
This selects one value. Adding both would count overlapping demand twice.