输入十个数,计算平均数,然后找大于平均的输出,并计数。---------------------------------------------------------importjavax.swing.JOptionPane;publicclasstest29{publicstati...
输入十个数,计算平均数,然后找大于平均的输出,并计数。
---------------------------------------------------------
import javax.swing.JOptionPane;
public class test29{
public static void main( String args[])
{
int count=0;
double sum=0;
double aver=0;
double[] a=new double[10];
for(int i=0;i<=9;i++){
String Value=JOptionPane.showInputDialog(null,"输入一个整数:","test",JOptionPane.QUESTION_MESSAGE);
a[i]=Double.parseDouble(Value);
sum+=a[i];
}
aver=sum/10;
System.out.println(aver);
for(int i=0;i<=9;i++){
if(a[i]>aver)
System.out.println(a[i]);
count++;
}
System.out.println("there are "+count+" numbers" );
}
}
-------------------------------------------
依次输入:10 20 30 40 50 60 70 80 90 100
输出:
55.0
60.0
70.0
80.0
90.0
100.0
there are 10 numbers
--------------------------
大于55的数应该是5个啊??
展开