判斷某一年是 “平年”||“閏年”,一月有多少天,
using System;
using System.Threading.Tasks.Sources;
namespace stars
{
class Program
{
static void Main(string[] args)
{
//for回圈只是為了在控制臺回圈輸出;
for (; ; )
{
//這是正式開始的原始碼;
//控制臺輸出年份和月份;
Console.WriteLine("輸入年份?");
int year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("輸入月份?");
int month = Convert.ToInt32(Console.ReadLine());
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
Console.WriteLine("{0}年,{1}月有31天", year, month);
break;
case 2:
if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0)
{
//判斷閏年的2月有29天;
Console.WriteLine("{0}是閏年,2月有29天", year);
}
else
{
//判斷平年的2月有28天;
Console.WriteLine("{0}是平年,2月有28天", year);
}
break;
default:
Console.WriteLine("{0}年,{1}月有30天", year, month);
break;
}
Console.ReadLine();
}
}
}
}
運行結果:
輸入年份?
2012
輸入月份?
2
2012是閏年,2月有29天
輸入年份?
2020
輸入月份?
2
2020是閏年,2月有29天
輸入年份?
2021
輸入月份?
2
2021是平年,2月有28天
輸入年份?
2021
輸入月份?
9
2021年,9月有30天
輸入年份?
2021
輸入月份?
8
2021年,8月有31天```
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/139764.html
標籤:其他
上一篇:我的所有的瀏覽器被hao123 挾持了,終極解決方案
下一篇:bool型別在VS中引發的血案
