DateTime date = DateTime.Parse(Console.ReadLine()); //输入生日日期 int month = date.Month; //获取生日月份 int day = date.Day; //获取生日日期

string constellation = ""; //初始化星座字符串

switch (month) { case 1: if (day <= 19) constellation = "魔羯座"; else constellation = "⽔瓶座"; break; case 2: if (day <= 18) constellation = "⽔瓶座"; else constellation = "双⻥座"; break; case 3: if (day <= 20) constellation = "双⻥座"; else constellation = "⽩⽺座"; break; case 4: if (day <= 19) constellation = "⽩⽺座"; else constellation = "⾦⽜座"; break; case 5: if (day <= 20) constellation = "⾦⽜座"; else constellation = "双⼦座"; break; case 6: if (day <= 21) constellation = "双⼦座"; else constellation = "巨蟹座"; break; case 7: if (day <= 22) constellation = "巨蟹座"; else constellation = "狮⼦座"; break; case 8: if (day <= 22) constellation = "狮⼦座"; else constellation = "处⼥座"; break; case 9: if (day <= 22) constellation = "处⼥座"; else constellation = "天秤座"; break; case 10: if (day <= 23) constellation = "天秤座"; else constellation = "天蝎座"; break; case 11: if (day <= 22) constellation = "天蝎座"; else constellation = "射⼿座"; break; case 12: if (day <= 21) constellation = "射⼿座"; else constellation = "魔羯座"; break; }

Console.WriteLine(constellation); //输出星座名

c#switch语句输⼊⼀个⽣⽇⽇期输出其星座 ⽩⽺座321-419⾦⽜座420-520双⼦座521-621巨蟹座622-722 狮⼦座723-822处⼥座823-922天秤座923-1023天蝎座1024-1122 射⼿座1123-1221魔羯座1222-119⽔瓶座120-218双⻥座219-320

原文地址: http://www.cveoy.top/t/topic/fiAe 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录