Print the Name of Month Based on Entered Number

import 'dart:io';//1
main()
{
  print("Enter a Number");//2
   var number = int.parse(stdin.readLineSync());//3
   var monthName ="January";//4
   switch(number)//5
   {
     case 1:
       monthName="January";
       break;
     case 2:
       monthName = "Febraury";
       break;
     case 3:
       monthName = "March";
       break;
     case 4:
       monthName = "April";
       break;
     case 5:
       monthName = "May";
       break;
     case 6:
       monthName = "June";
       break;
     case 7:
       monthName = "July";
       break;
     case 8:
       monthName = "August";
       break;
     case 9:
       monthName = "September";
       break;
     case 10:
       monthName = "October";
       break;
     case 11:
       monthName = "November";
       break;
     case 12:
       monthName = "December";
       break;
     default:
       monthName = "Wrong input";
       break;
   }
   if(number<=0 || number>12)//6
     {
       print("$monthName");//7
     }
   else
     {
       print("$number month name is=$monthName");//8
     }

}
  1. Import statement for input and output library
  2. Instruct the user to enter a number
  3. After converting user input into an int and then assigned to number variable
  4. Create and initialize a monthName variable with the value “January”
  5. Switch Statement to change the monthName value according to user choice
  6. if Statement to Check user enter the valid number or not
  7. Show Wrong input message on the console
  8. Show Enter number with M

Output

Enter a Number
20
Wrong input

Enter a Number
12
12 month name is=December

Leave a Reply

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