Print the Name of Month Based on Entered Number

fun main()
{
    println("Enter a Number")//1
    val number = readLine()!!.toInt()//2
    var dayName = when(number){//3
        1-> "Sunday"
        2-> "Monday"
        3-> "Tuesday"
        4-> "Wednesday"
        5->"Thursday"
        6->"Friday"
        7->"Saturday"
        else-> "Sorry Wrong Input"

    }
    print(dayName)//4
}

  1. Instruct the user to enter a number
  2. Convert the user to enter into int and assign to number variable
  3. Create and initialize the value of dayName from when expression result
  4. Print the output on the console

Output

Enter a Number
5
Thursday

Enter a Number
78
Sorry Wrong Input

Leave a Reply

Your email address will not be published. Required fields are marked *