加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
WhatDay.cs 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
using System;
using System.Collections.Generic;
using System.Text;
namespace c_sharp_experiment03_3
{
enum MonthName {
January,February,March,April,May,June,July,August,September,October,November,December
}
class WhatDay {
static System.Collections.ICollection DaysInMonths = new int[12] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static void Main(string[] args) {
try
{
Console.Write("Please input a day number between 1 and 365:");
string line = Console.ReadLine();
int dayNum = int.Parse(line);
if (dayNum < 1 || dayNum > 365)
{
throw new ArgumentOutOfRangeException("Day out of Range");
}
int monthNum = 0;
foreach (int daysInMonth in DaysInMonths)
{
if (dayNum <= daysInMonth)
{
break;
}
else
{
dayNum -= daysInMonth;
monthNum++;
}
}
MonthName temp = (MonthName)monthNum;
string monthName = Enum.Format(typeof(MonthName), temp, "g");
Console.WriteLine("{0} {1}", dayNum, monthName);
Console.Read();
}
catch (Exception e) {
Console.WriteLine(e);
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化