题目描述 It is said that 90% of frosh expect to be above average in their class. You are to provide a reality check. 输入 The first line of standard input contains an integer C, the number of test cases. C data sets follow. Each data set begins with an integer, N, the number of people in the class (1 <= N <= 1000). N integers follow, separated by spaces or newlines, each giving the final grade (an integer between 0 and 100) of a student in the class. 输出 For each case you are to output a line giving the percentage of students whose grade is above average, rounded to 3 decimal places. 样例输入 55 50 50 70 80 1007 100 95 90 80 70 60 503 70 90 803 70 90 819 100 99 98 97 96 95 94 93 91样例输出 40.000%57.143%33.333%66.667%55.556%

解决方案 »

  1.   

    to output a line giving the percentage of students whose grade is above average
    输出成绩高于平均成绩的人数百分比。
      

  2.   

    import ...
    import ....
    public class Main{
       public static void main(String []args){
           Scanner cin=new Scanner(System.in);
           int C=cin.nextInt();
           int n=0;
           for(int i=0; i<C; i++){
                 n=cin.nextInt();
                 int sum=0;
                 for(int j=0; j<n; j++){
                    sum+=cin.nextInt();
                          
                  }
                  ...........
                  ......
              }    }}
      

  3.   

    在楼上的提示下,这道题我做出来了。我的代码如下:/*
     * 计算高于平均分的学生的比例
     */
    public static ArrayList average(){
    ArrayList array = new ArrayList();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try {
    System.out.println("请输入要测试数据的个数:");
    int n = Integer.parseInt(br.readLine());
    for(int i = 0;i<n;i++){
    System.out.println("请输入第"+(i+1)+"组测试用例:");
    String str = br.readLine();
    String[] strs = str.split(" ");
    int total = 0;//计算总分数
    for(int j = 1;j<strs.length;j++){
    total += Integer.parseInt(strs[j]);
    }
    //计算平均分
    float average = total / (float)Integer.parseInt(strs[0]);
    int greaderAverageSum = 0;//高于平均分的总分数
    for(int j = 1;j<strs.length;j++){
    if(Integer.parseInt(strs[j]) > average){
    greaderAverageSum ++;
    }
    }
    //高于平均数的学生占的比例
    //创建数字格式化实例对象
    BigDecimal greaderAverage = new BigDecimal((double)greaderAverageSum * 100 / Integer.parseInt(strs[0]));
    greaderAverage = greaderAverage.setScale(3,4);//四舍五入,保留两位
    //用集合保存结果
    array.add(greaderAverage + "%");
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    return array;
    }