统计信息

  • 访问数:14554
  • 博客数:143
  • 建立时间:2008-01-05
  • 更新时间:2008-10-15
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

P6Q04

2008-04-14 17:03:29

天气: 晴朗 心情: 高兴

/*Filename:P6Q04
 * Name:Wang Chaoran
Description:4 (Analyzing scores)
Write a program that reads an unspecified number of
scores and determines how many scores are above or
equal to the average and how many scores are below the
average. Enter a negative number to signify the end of the input.
Assume that the maximum number of scores is 100.
*/
import java.util.Scanner;
class P604{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    double sum = 0;
    int count = 0;
    double score = 0;

    double[] input = new double[100];
    while(score>=0&&count<=100-1){
      System.out.println("Enter a score "+(count+1)+" (Enter a negative number(not counted) to signify the end of the input):");
      score = scan.nextDouble();
      if(score<0){
         System.out.println("You have entered a negative number to signify the end of the input!");
        }
      else{
        sum+=score;
        input[count]=score;
        count++;       
      }
      
      }
        int countAbove = 0;
        System.out.println("You have entered "+count+" numbers:");
        for(int i=0;i<count;i++){
        System.out.print(input[i]+" ");
        if (input[i]>= sum/count)
          countAbove++;
    }
       
         System.out.println("\nAverage value is: "+(sum/count));
         System.out.println(countAbove+" scores are above or equal to the average.");
         System.out.println("And "+(count-countAbove)+" scores are below the average.");
  }
}


加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd