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

  • 相关阅读:
    openVolumeMesh example 程序学习
    使用字符串创建java 对象
    HDU-1501-Zipper
    UVA-10285-Longest Run on a Snowboard
    HDU-2182-Frog
    HDU-2044-一只小蜜蜂
    POJ-1163-The Triangle
    HDU-1159-Common Subsequence
    HDU-2069-Coin Change
    HDU-4864-Task
  • 原文地址:https://www.cnblogs.com/runy/p/1530861.html
Copyright © 2011-2022 走看看