Mapping month numbers to seasons

Report a typo

Write a program that takes an integer as input representing a month number (1-12) and prints the corresponding season using a when expression. Months 12, 1, 2 are winter; 3, 4, 5 are spring; 6, 7, 8 are summer; and 9, 10, 11 are fall.

Sample Input 1:

3

Sample Output 1:

Spring

Sample Input 2:

7

Sample Output 2:

Summer
Write a program in Kotlin
import java.util.Scanner

fun main() {
val scanner = Scanner(System.`in`)

// Read the input month number
val monthNumber = scanner.nextInt()

// Use a when expression to determine the corresponding season
val season = when (monthNumber) {
// TODO: Add cases for each month range and the corresponding season
else -> "Invalid month number"
}

println(season)
}

Create a free account to access the full topic