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;
                    }
                }

  • 相关阅读:
    xcode 查看stastic
    erlang 游戏服务器开发
    同一世界服务器架构--Erlang游戏服务器
    理解Erlang/OTP
    使用SecureCRT连接AWS的EC2
    redis单主机多实例
    Redis命令总结
    [redis] redis配置文件redis.conf的详细说明
    [转至云风的博客]开发笔记 (2) :redis 数据库结构设计
    Redis 集群方案
  • 原文地址:https://www.cnblogs.com/runy/p/1530861.html
Copyright © 2011-2022 走看看