• 例题:输入身份证号码,判断你是什么生肖。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();

  • 相关阅读:
    postgresql强制删除数据库
    oracle ORA-31655
    oracle 删除表空间与用户
    Nginx 配置文件说明
    docker学习笔记---基本命令
    SSH的 Write failed: Broken pipe 问题
    nginx 修改文件上传大小限制
    "echo 0 /proc/sys/kernel/hung_task_timeout_secs" disable this message
    Centos8 配置静态IP
    Prometheus Node_exporter 详解
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4426301.html
Copyright © 2020-2023  润新知