从多次使用的单个变量中获取百分比

时间:2014-11-25 06:03:10

标签: java logic percentage

请阅读我的代码,以便了解我的问题(java语言)

for (int i=1; i <= studentnum; i++)
{
// ask and get the initials from the user
System.out.print("Enter the student initals  ");
String initials = input.next();

// ask and get the student points from the user
System.out.print("Enter student Points  ");
points=input.nextInt();

//calculate the percentage and the letter grade for each student
percent = (points / maxpoints)*100;

    if (points > maxpoints || points < 0)
    {
    System.out.println("invalid student points");
    studentnum = studentnum + 1;
    }

    else if (percent >=90)
    {   String grade ="A";
    System.out.printf(result, initials, points, percent, grade);
     }

    else if (percent >=80)
    {   String grade ="B";
    System.out.printf(result, initials, points, percent, grade);
    }

    else if (percent >=70)
    {   String grade ="C";
    System.out.printf(result, initials, points, percent, grade); 
    }

    else if (percent >=60)
    {   String grade ="D";
    System.out.printf(result, initials, points, percent, grade);
    }

    else // (percent <=59)
        {   String grade ="F";
    System.out.printf(result, initials, points, percent, grade);
    }
}

我得到studentnum作为输入,我需要计算课程&#39;平均百分比,我需要计算所有给变量点的值(学生点数) (我不能给点赋予不同的值,因为循环的数量可能是不定的)。 抱歉,如果这令人困惑。

0 个答案:

没有答案