码迷,mamicode.com
首页 > 其他好文 > 详细

例题:输入身份证号码,判断你是什么生肖。switch,case练习,substring 类使用联系,会用取余

时间:2015-04-14 23:18:10      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

 Console.WriteLine("请输入您的身份证号码");

            string x = Console.ReadLine();

            string year=x.Substring (6,4);//从身份证的第六位开始截取,往后截取四位,就是你的出生年份

            int x1 = Convert.ToInt32(year);//把截取到年份代入到x1中,            

            string sx = "";

            switch(x1%12)//输入一个年份取余,如果假设取余为四,你能判断那年的生肖,然后根据十二生肖排列,判断取余为0到12分别为哪个生肖

            {

                case 0:

                sx="狗";

                    break;

                case 1:

                    sx = "鸡";

                    break;

                case 2:

                    sx = "猴";

                    break;

                case 3:

                    sx = "羊";

                    break;

                case 4:

                    sx = "马";

                    break;

                case 5:  

                   sx = "蛇";

                    break;

                case 6:  

                   sx = "龙";

                    break;

                case 7:  

                   sx = "兔";  

                   break;  

               case 8:

                    sx = "虎";

                    break;

                case 9:   

                  sx = "牛";

                    break;

                case 10:

                    sx = "鼠";

                    break;  

               case 11:

                    sx = "猪";   

                  break;  

               default :

                    sx = "请输入正确的年份";

                    break;

 

            }            

Console.WriteLine("您的生肖是"+sx);

            Console.ReadLine();

例题:输入身份证号码,判断你是什么生肖。switch,case练习,substring 类使用联系,会用取余

标签:

原文地址:http://www.cnblogs.com/275147378abc/p/4426301.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!