C#实现按照年份计算生肖属相的要领

时间:2022-03-06 08:19:29

供给年份可以输出属相,代码对照简单,因为2008年为鼠年,所以措施以2008为标准开始,2008对中国人也有特殊的意义

private static void shuxiang(int year) { string[] shuxiang = {"鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"}; int tmp = year - 2008; if (year < 2008) { Console.WriteLine(shuxiang[tmp % 12 + 12]); } else { Console.WriteLine(shuxiang[tmp % 12]); } }