How to print the season name of the year based on the month number in Kotlin

1 Answer

0 votes
fun printSeason(month: Int) {
    when (month) {
        12, 1, 2 -> println("Winter")
        3, 4, 5 -> println("Spring")
        6, 7, 8 -> println("Summer")
        9, 10, 11 -> println("Autumn")
        else -> println("Invalid month number!")
    }
}

fun main() {
    val month = 9
    
    printSeason(month)
}



/*
run:

Autumn

*/

 



answered Sep 10, 2025 by avibootz
...