import java.awt.*;
import javax.swing.*;
public class Test7_38 {
public static void main(String[] args) {
double scorse[] = new double[100];
int count = 0;
double sum = 0, ave = 0;
int CountMin = 0, CountMax = 0;
double result = Double.parseDouble(JOptionPane.showInputDialog(null,
"请输入一个分数:"));
while (result > 0) {
scorse[count] = result;
count++;//在此count=count+1;
System.out.println(""+scorse[count]+" "+count);//[color=Red]每次执行到这里时,你所取的其实是score[count+1]但是此时的score[count+1]中还没放入值为0,并不是取的你已经放入值的score[count]。所以下边的语句是已经执行了不过是执行的0+0=0
sum=sum+scorse[count];
ave=sum/count;
if ((ave > 0) && (ave < scorse[count])) CountMin++;
if ((ave > 0) && (ave > scorse[count])) CountMax++;
if (result < 0) break;
result = Double.parseDouble(JOptionPane.showInputDialog(null,
"请输入一个数:"));
}
for (int i = 0; i < count; i++)
System.out.print(scorse + " ");
System.out.println("sum="+sum);
System.out.println(" Average="+ave);
System.out.println("平均分以上的有"+CountMax+"人,平均分以下的有"+CountMin+"人");
}
}
其实你在碰到问题自己多运行几遍,想一想就会有答案的 |