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

     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();

  • 相关阅读:
    html5储存篇(二)
    html5 存储篇(一)
    【刷题计划1】【poj分类转载】【8月20号开始】
    【如何搭建一个属于自己的独立博客~~~基于windows系统,使用wordpress建站】【弱菜一枚~~大神请路过】
    第六章 6.6 图的应用
    第六章 6.5 图的遍历
    第六章 6.4 图的存储结构
    poj 2488 A Knight's Journey 【dfs】【字典序】【刷题计划】
    【Educational Codeforces Round 33 B】Beautiful Divisors
    【 Educational Codeforces Round 33 A】Chess For Three
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4426301.html
Copyright © 2011-2022 走看看