C# 编写一个控制台应用程序,在屏幕上输入你的出生日期,判断并输出你的生日是星期几(中文)
时间: 2024-02-20 16:56:30 浏览: 18
好的,下面是 C# 控制台应用程序的代码:
```csharp
using System;
class Program
{
static void Main(string[] args)
{
Console.Write("请输入您的出生日期(格式:YYYY-MM-DD):");
string input = Console.ReadLine();
if (!DateTime.TryParse(input, out DateTime birthday))
{
Console.WriteLine("输入的日期格式不正确!");
return;
}
string[] weekdays = new string[] { "天", "一", "二", "三", "四", "五", "六" };
int weekday = (int)birthday.DayOfWeek;
Console.WriteLine($"您的生日是星期{weekdays[weekday]}");
}
}
```
运行程序后,按照提示输入出生日期,程序会自动判断并输出生日是星期几(中文)。
相关问题
c#写一个控制台应用程序,在屏幕上输入年、月、日,输出下一个闰年是那一年
好的,以下是代码实现:
```csharp
using System;
namespace NextLeapYear
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入年份:");
int year = int.Parse(Console.ReadLine());
int nextLeapYear = year;
while (!IsLeapYear(nextLeapYear))
{
nextLeapYear++;
}
Console.WriteLine("{0}年之后的下一个闰年是{1}年", year, nextLeapYear);
}
// 判断是否为闰年
static bool IsLeapYear(int year)
{
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
}
}
```
在控制台中输入年份,程序会输出该年份之后的下一个闰年是哪一年。
c#写一个控制台应用程序,在屏幕上输入年、月、日,输出下一个闰年是那一年
好的,下面是代码:
```csharp
using System;
namespace NextLeapYear
{
class Program
{
static void Main(string[] args)
{
Console.Write("请输入年份:");
int year = int.Parse(Console.ReadLine());
Console.Write("请输入月份:");
int month = int.Parse(Console.ReadLine());
Console.Write("请输入日期:");
int day = int.Parse(Console.ReadLine());
while (!IsLeapYear(year + 1))
{
year++;
}
Console.WriteLine($"{year + 1}年是下一个闰年。");
}
static bool IsLeapYear(int year)
{
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
}
}
```
这个程序会让用户输入一个年月日,然后计算出下一个闰年是哪一年,并输出结果。它使用了一个 `IsLeapYear` 方法来判断一个年份是否是闰年,然后通过循环不断增加年份,直到找到下一个闰年为止。