输入学号、姓名和成绩,要求成绩不能为负数,如果为负数则提示重新输入,直到输入正确为止。要求:使用异常处理机制,使得不论有何异常情况,程序均能正常运行结束。
try
{
int Score = -1;
Console.WriteLine("请输入学号:");
string StuNo = Console.ReadLine();
Console.WriteLine("请输入姓名:");
string StuName = Console.ReadLine();
while (Score < 0)
{
Console.WriteLine("请输入成绩:");
Score = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("StuNo:{0},StuName:{1},Score:{2}", StuNo, StuName, Score);
}
catch(Exception e){
Console.WriteLine(e);
}
电子邮箱:[email protected]
简介:中华人民共和国公民,中国共青团员,CSDN博客专家,秦淮区疾控中心托管社会公益组织指南针工作室志愿者,在校大学生,参与过微信小程序《约车吗》、《指南针微公益》、《智慧庆云禅寺》的开发。