zoukankan      html  css  js  c++  java
  • 判断输入字符串是否等效Int32位数字的两种方法

    Code1
                for (int i = 0; i < 10; )
                {
                    string str = Console.ReadLine();
                    int num;
                    if (int.TryParse(str, out num) == false)
                    {
                        Console.WriteLine("输入的不是数字,请重新输入!");

                    }
                    else
                    {
                        {
                            if (num % 2 == 0)
                            {
                                Console.WriteLine("偶数");
                            }
                            else
                            {
                                Console.WriteLine("奇数");
                            }
                        }
                    }
                    i++;
                }


    Code2

            int temp=0;
                while (temp == 0)
                {
                    string input = Console.ReadLine();
                    try
                    {
                        int num = int.Parse(input);
                        temp++;
                    }

                    catch
                    {
                        Console.WriteLine("您输入的不是数字,请重新输入!");
                        temp = 0;
                    }
                }

  • 相关阅读:
    PAT《数据结构学习与实验指导》实验项目集 2-09 2-10 2-11 2-12 2-13
    codeblocks+Mingw 下配置开源c++单元测试工具 google test
    编程之美 1.16 24点游戏
    PAT 1065 1066 1067 1068
    多线程批量执行等待全部结果
    使用Git和远程代码库
    CentOS下Crontab安装使用详细说明(转)
    安装和测试Kafka(转)
    MapReduce任务参数调优(转)
    Maven构建应用程序常用配置(转)
  • 原文地址:https://www.cnblogs.com/runy/p/1530861.html
Copyright © 2011-2022 走看看