我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*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.");
}
}
导入论坛查看(60)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing