Find the Name of Day Based on the Entered number

import 'dart:io';//1
main()
{
  print("Enter a Number");//2
  var number = int.parse(stdin.readLineSync());//3
  var dayName ="Sunday";//4
  switch(number)//5
  {
    case 1:
      dayName="Sunday";
      break;
    case 2:
      dayName = "Monday";
      break;
    case 3:
      dayName = "Tuesday";
      break;
    case 4:
      dayName = "Wednesday";
      break;
    case 5:
      dayName = "Thursday";
      break;
    case 6:
      dayName = "Friday";
      break;
    case 7:
      dayName = "Saturday";
      break;
    default:
      dayName = "Wrong input";
      break;
  }
  if(number<=0 || number>7)//6
  {
    print("$dayName");//7
  }
  else
  {
    print("$number Day name is=$dayName");//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 dayName variable with value “Sunday”
  5. Switch Statement to change the dayName 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 Day Name

Output

Enter a Number
78
Wrong input

Enter a Number
1
1 Day name is=Sunday

Leave a Reply

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