一道C#的小习题?初学
来源:百度知道 编辑:UC知道 时间:2024/05/27 07:28:59
分数等级为A B C D E 五个等级,90-100为A 80-89为B,70-79为C 60-69为D
0-59为E (使用seitch...case语句)
是使用(switch...case)语句
为什么要用switch??
流程分支语句很多,有三元运算符,if else,switch
而使值有范围的判断只能用if else
using System;
class HelloWorld
{
static void Main(string[] args)
{
start:
Console.WriteLine("请输入数据");
try
{
byte btPoint = byte.Parse(Console.ReadLine().Trim());//将输入的数据转换为byte类型
if (btPoint > 100 || btPoint == 0)
{
Console.WriteLine("不属于范围之类或无意义的数");
goto start;
}
if (btPoint > 89 && btPoint < 101)
{
Console.WriteLine("A");
}
else if (btPoint > 79 && btPoint < 90)
{
Console.WriteLine("B");
}
else if (btPoint > 69 && btPoint < 80)
{
Console.Wr