SWITCH练习(一年第几天的判断)(switch语句判断星期几)

网友投稿 674 2022-09-11

SWITCH练习(一年第几天的判断)(switch语句判断星期几)

SWITCH练习(一年第几天的判断)(switch语句判断星期几)

using System;

namespace program

{

class program1

{

static void Main(string[] args)

{

program1 fenshu = new program1();

fenshu.Panduan();

program1 tian = new program1();

tian.Tianshu();

}

///

/// 计算一年中的第几天

///

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 = 365;

if ((total % 4 == 0 && total % 100 != 0) || (total % 400 == 0))//是否闰年的判断

{

total = 366;

}

switch (b)

{

case 1: total -= 31; goto case 2;

case 2:

if ((total % 4 == 0 && total % 100 != 0) || (total % 400 == 0))//闰年二月份有29天

total -= 29; //一层可以不使用块

else

total -= 28;

goto case 3;

case 3: total -= 31; goto case 4;

case 4: total -= 30; goto case 5;

case 5: total -= 31; goto case 6;

case 6: total -= 30; goto case 7;

case 7: total -= 31; goto case 8;

case 8: total -= 31; goto case 9;

case 9: total -= 30; goto case 10;

case 10: total -= 31; goto case 11;

case 11: total -= 30; goto case 12;

case 12: total -= 31; goto default;

default: total += c; break;

}

Console.WriteLine("{0}年{1}月{2}日是一年的第{3}天", a, b, c, total);

}

///

/// 练习switch

///

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;

}

}

}

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Android 11.0 删除上拉,进入全部应用界面
下一篇:批处理之批量修改文件扩展名
相关文章

 发表评论

暂时没有评论,来抢沙发吧~