循环分配计数条目

时间:2016-10-05 19:36:09

标签: loops

我有一个作业,我应该输入成绩并输出每个成绩的数量和该成绩的百分比。输入负数时,循环应停止。我想我现在已经拥有它,但我无法编译它。

import java.util.Scanner;
public class Homework6_Project1  
{

    public static void main (String[] args) 
    {
        Scanner Keyboard = new Scanner(System.in);
        double count = Keyboard.nextDouble();
        gradecounter:
        do
        {
        for (int i = 0; i < count; i++)
        {
        System.out.println("Enter the grade:");
        int Grade = Keyboard.nextInt();
    }
        if  (Grade >=90)
        {
            int CountA = 0;
            int A = Grade;
            double AverageA = A/count;
            ++CountA;
        }
        if (Grade<89 && Grade>=80)
        {
            int CountB = 0;
            int B = Grade;
            double AverageB = B/count;
            ++CountB;
    }
        if (Grade < 80 && Grade >=70)
        {
            int CountC = 0;
            int C = Grade;
            double AverageC = C/count;
            ++CountC;
        }
        if (Grade < 70 && Grade >= 60)
        {
            int CountD = 0;
            int D = Grade;
            double AverageD = D/count;
            ++CountD;
        }
        if (Grade < 60 && Grade >= 0)
        {
            int CountF = 0;
            int F = Grade;
            double AverageF = F/count;
            ++CountF;
        }
        while (Grade < 0)
        {
            System.out.println("Count of A grade's:" + " " + CountA + " Percentage of A's:" + " " + AverageA);
            System.out.println("Count of B grade's:" + " " + CountB + " Percentage of B's:" + " " + AverageB);
            System.out.println("Count of C grade's:" + " " + CountC + " Percentage of C's:" + " " + AverageC);
            System.out.println("Count of D grade's:" + " " + CountD + " Percentage of D's:" + " " + AverageD);
            System.out.println("Count of F grade's:" + " " + CountF + " Percentage of F's:" + " " + AverageF);
            break gradecounter;
    }
}
}
}

0 个答案:

没有答案