现在的位置: 首页 > 综合 > 正文

表驱动法(zz:http://www.cnblogs.com/shinn/archive/2008/04/16/1157141.html)

2012年11月01日 ⁄ 综合 ⁄ 共 429字 ⁄ 字号 评论关闭

private static double[] rangeLimit = {  60.0, 75.0, 85.0, 95.0,100.0 };
private static string[] grade = {"不合格", "合乎要求", "良好", "优秀" ,"卓越"};
private static readonly int maxLevel = grade.Length - 1;
public static string CalculateGrade(double score)
{
   int level = 0;
   while (level <= maxLevel)
    {
          if (score < rangeLimit[level])
           {
               return grade[level];
           }
          else

         {

             level++;

          }
    }
    return grade[maxLevel];
}

抱歉!评论已关闭.