static void Main(string[] arg) { //while的3个练习 Console.WriteLine("请输入班级人数:"); int intNum = 0; while (!(int.TryParse(Console.ReadLine(), out intNum))) { Console.WriteLine("班级人数输入有误, 请重新输入!"); }; int i = 0; int sum = 0; int score = 0; while (i<intNum) { Console.WriteLine("请输入第{0}个学生的成绩", i + 1); while (!(int.TryParse(Console.ReadLine(), out score))) { Console.WriteLine("第{0}个同学成绩输入有误, 请重新输入!", i + 1); } sum += score; i++; } Console.WriteLine("{0}个同学的总成绩是{1},平均成绩是{2};", i , sum, sum / i ); Console.ReadKey(); }
标签:intNum,Console,int,练习,while,循环,WriteLine From: https://www.cnblogs.com/csflyw/p/18354470