程序代码:
while (i < 10) { try//try-catch { Console.WriteLine("请输入第{0}个正整数。", i); shu = Convert.ToInt32(Console.ReadLine()); } catch { Console.WriteLine("输入错误,请重新输入一个正整数。"); i = 1; //改成你的初始值 continue; } if (shu > a) { a = shu; } i++; }
//还是用goto方便啊 第几个错了 就从第几个重新输入 static void Main(string[] args) { int i = 0; int shu = 0; int a = 1; while (i < 10) { input: try//try-catch { Console.WriteLine("请输入第{0}个正整数。", i); shu = Convert.ToInt32(Console.ReadLine()); } catch { Console.WriteLine("输入错误,请重新输入一个正整数。"); goto input; } if (shu > a) { a = shu; } i++; } }