附上自己写的代码。可以看看。
- double number = 0.0;
- bool result = false;
- string exit = "";
- do
- {
- try
- {
- Console.WriteLine("请输入数字");
- number = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("数字为{0},2倍是{1}", number, number * 2);
- result = true;
- }
- catch
- {
- exit = Convert.ToString(number);
- if (exit != "q")
- {
- Console.WriteLine("输入不是有效数字");
- }
- else
- {
- Console.WriteLine("输入结束");
- }
- result = false;
- }
- }
- while (result);
- Console.ReadKey();
复制代码 |
|