Monday, March 25, 2013
C#: Check the month, input from the keyboard how many days
//Lets enter the month and year from the keyboard. Check to see that month how many days.
class Program {
static void Main () {
int m, y;
Console.Write ("Enter a month:");
m = int.Parse (Console.ReadLine ());
Console.Write ("Enter the year:");
y = int.Parse (Console.ReadLine ());
switch (m) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
Console.WriteLine ("{0} No 31 Date", m);
break;
case 4:
case 6:
case 9:
case 11:
Console.WriteLine ("30-day months {0}", m);
break;
case 2:
if ((y% 4 == 0 && y% 100! = 0) | | (y% 400 == 0))
Console.WriteLine ("{0} No 29 Date", m);
else
Console.WriteLine ("{0} No 28 Date", m);
break;
}
Console.ReadLine ();
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment