SWITCH练习(一年第几天的判断)
2024-09-06 09:17:30
using System;
namespace program
{
class program1
{
static void Main(string[] args)
{
program1 fenshu = new program1();
fenshu.Panduan();
program1 tian = new program1();
tian.Tianshu();
}
/// <summary>
/// 计算一年中的第几天
/// </summary>
void Tianshu()
{
Console.Write("请输入年份=");
int a = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入月份=");
int b = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入日=");
int c = Convert.ToInt32(Console.ReadLine());
int total = ;
if ((total % == && total % != ) || (total % == ))//是否闰年的判断
{
total = ;
}
switch (b)
{
case : total -= ; goto case ;
case :
if ((total % == && total % != ) || (total % == ))//闰年二月份有29天
total -= ; //一层可以不使用块
else
total -= ;
goto case ;
case : total -= ; goto case ;
case : total -= ; goto case ;
case : total -= ; goto case ;
case : total -= ; goto case ;
case : total -= ; goto case ;
case : total -= ; goto case ;
case : total -= ; goto case ;
case : total -= ; goto case ;
case : total -= ; goto case ;
case : total -= ; goto default;
default: total += c; break;
}
Console.WriteLine("{0}年{1}月{2}日是一年的第{3}天", a, b, c, total);
}
/// <summary>
/// 练习switch
/// </summary>
void Panduan()
{
Console.Write("请输入学生等级的值=");
string a = Console.ReadLine();
switch (a)
{
case "A": Console.WriteLine("85-100"); break;
case "B": Console.WriteLine("70-84 "); break;
case "C": Console.WriteLine("60-69"); break;
case "D": Console.WriteLine("不及格"); break;
default: Console.WriteLine("输入有误"); break;
}
}
}
}
最新文章
- c++用法的学习心得
- make命令以及makefile
- 例子:Database - Linq to sql
- 【读书笔记】iOS-头文件导入-@class注意事项
- 监听turtlesim仿真器,发送数据到实际的机器人--20
- 5个基于css3超炫的鼠标滑动按钮动画
- vi编辑器基本用法介绍
- 一步步学习NHibernate(1)&mdash;&mdash;NHibernate介绍
- 【从0開始Tornado建站】群聊
- 使用javaDate类代数据仓库维度表
- TypeScript入门(二)函数新特性
- ●CodeForces 429D Trick_Function
- 二进制数据的序列化反序列化和Json的序列化反序列化的重要区别
- emWin收音机,含uCOS-III和FreeRTOS两个版本
- 2.3 i++/i--与++i/--i的运算
- C++面试基础之回调
- 使用FluentMigrator进行数据库迁移
- rabbitmq学习(七) —— springboot下的可靠使用
- 把旧系统迁移到.Net Core 2.0 日记 (16) --Cors跨域访问
- 百度全站 https FAQ:技术宅告诉你如何搜索更安全