编写一个控制台程序,实现以下功能

(1)、读入字符串A.
(2)、如果A等于”exit”则退出程序。
(3)、读入字符串B
(4)、如果A和B是数字,则将A和B转换为数字X和Y,否则输出错误信息,然后跳到(6)。
(5)、输出X + Y的结果。
(6)、重复上述操作。

 class StringAndInt
    {
        //========================================================================
        //  メソッド名 : Main
        /// <summary>
        /// 实现
        /// </summary>
        /// <remarks>
        /// 参数needReflesh,判断是否为true还是false
        /// 字符串a、b
        /// </remarks>
        /// <param name="args"></param>
        //========================================================================
        static void Main(string[] args)
        {
            bool needReflesh = true;

            while (needReflesh)
            {
                Console.Write("Please Input a:");

                string a = Console.ReadLine(); //输入a

                if (a == "exit")               //如果a为exit,则退出程序
                {
                    return;
                }

                Console.Write("Please Input b:");

                string b = Console.ReadLine(); //输入b

                int x;                         //用于存放a转换后的数字
                int y;                         //用于存放b转换后的数字

                if (int.TryParse(a, out x) == true && int.TryParse(b, out y) == true)
                {
                    Console.WriteLine(" x + y = " + (x + y));
                    continue;
                }
                else
                {
                    Console.WriteLine("WARNING!");
                    continue;
                }
            }
        }
    }


 

猜你喜欢

转载自blog.csdn.net/JasmineDawn/article/details/7211163