闰年与月份判断

Console.WriteLine("您想知道哪年");

try {

int year = Convert.ToInt32(Console.ReadLine());

try {

Console.WriteLine("请输入月份");

int month = Convert.ToInt32(Console.ReadLine());

if (month >= 1 && month <= 12)

{

int day = 0;

switch (month)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12: day = 31;

break;

case 2:

if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))

{

day = 29;

}

else

{

day = 28;

}

break;

default: day = 30;

break;

}

Console.WriteLine("{0}年{1}月有{2}天", year, month, day);

}//判断月份是否输入错的括号

else {

Console.WriteLine("您输入的月份有误");

}

}//try月份的括号

catch

{

Console.WriteLine("您输入的月份有误,程序退出");

}

}

catch

{

Console.WriteLine("您输入的年份有误,程序退出");

}

Console.ReadKey();

时间: 2024-07-28 18:05:27

闰年与月份判断的相关文章

实例365(5)---------DateTime.IsLeapYear 方法判断是否是闰年,DaysInMonth判断一个月有几天,Addday取得前一天的日期GetYesterDay

一:DateTime.IsLeapYear 方法判断是否是闰年,截图 二:代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace GetDays { public

使用switch语句编程,根据输入的年份判断是否为闰年,根据输入的月份判断这月有多少天

#include <stdio.h> int main() { int year, month, flag = 0; printf("Enter Year And Month:!\n"); scanf("%d %d", &year, &month); if(year % 4 ==0 && year % 100 != 0 || year % 400 ==0) { flag = 1; printf("您所输入的年份是

C++入门经典-例3.5-判断某一年是否是闰年之嵌套判断

1:代码如下: // 3.5.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> using namespace std; void main() { int iYear; cout << "请输入年份" << endl; cin >> iYear; if(iYear%4==0) { if(iYear%100==0) { if(iYear%40

delphi 输入年月判断天数,判断指定年份与月份判断当月有多少天

delphi 输入年月判断天数 //需要引用dateutils: unit Unit1; interface uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs,dateutils, StdCtrls; type  TForm1 = class(TForm)    Label1: TLabel;    Label2: TLabel;    Label3: TLabel;

关于软件测试(4):闰年输入的判断以及非法输入的处理测试

针对这周的软件测试课程,讲解了非法输入的不正当处理会对程序造成不必要的损失,因此通过简单的闰年检测程序来处理关于闰年测试的非法输入. 一.需求分析 要求输入框输入年份,点击按钮,出现提示.并能有效的处理任何输入 二.测试用例 内容 取值 预期结果 被400整除 2000 是闰年 被100整除但不被400整除 1900 不是闰年 被4整除且不被100整除 1904 是闰年 不被4整除 1901 不是闰年 非数字字符 abc 非法输入 负数 -1234 非法输入 小数 2000.5 非法输入 空字符

用JS写,根据用户输入的年月份判断是这年的第几天

console.log("输入年份:"); let year = readline.question() - 0; console.log("输入一个月份"); let month = readline.question() - 0; console.log("输入天数"); let day = readline.question() - 0; if (year > 999 && year < 10000) { if

闰年的判断方法

①.普通年能被4整除且不能被100整除的为闰年.②.世纪年能被400整除的是闰年③.对于数值很大的年份,这年如果能整除3200,并且能整除172800则是闰年.如172800年是闰年,86400年不是闰年 题目:输入某年某月某日,判断这一天是这一年的第几天? 1.程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊 情况,闰年且输入月份大于3时需考虑多加一天. 2.程序源代码: #include <stdio.h> main() { int day,month

判断是否为闰年

#include <stdio.h>void main(){ int year=0; printf("请输入一个年份:\n"); scanf("%d",&year); if(year%4==0&&year%100!=0) { printf("%d是闰年!\n",year); } else if(year%400==0) { printf("%d是闰年!\n",year); } else {

C++刷题——2710: 函数---闰年判断

编写函数is_LeapYear实现其参数是否是闰年的判断,如果参数是闰年则返回1,如果不是闰年返回0. 在主函数输入年,调用函数is_LeapYear来进行判断是否是闰年,根据判断结果输出该年的二月份有几天. /* All rights reserved. * 文件名称:test.cpp * 作者:陈丹妮 * 完成日期:2015年 5 月 21 日 * 版 本 号:v1.0 */ #include <iostream> using namespace std; int is_LeapYear(