SWITCH练习(一年第几天的判断)
程序员文章站
2022-10-27 23:31:37
using System; namespace program { class program1 { static void Main(string[] args) { program1 fenshu = new program1(); fenshu.Panduan(); program1 tian ......
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 = 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); } /// <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; } } } }
上一篇: 下午茶时光,怎么能少得了自制小茶点