展开全部
引用1楼 christal yhy的答案,考虑到浮点数的存在,特在此基础上优化一下,代码如下:
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入62616964757a686964616fe59b9ee7ad9431333262373933要输入的个数:");
int count = scan.nextInt();
System.out.println("请输入" + count + "个正数(按回车键输入下一个)");
double[] array = new double[count];
for (int i = 0; i
array[i] = scan.nextDouble();
}
double num = 0;
double avg = 0;
for (int i=0;i
num=array[i]+num;
}
java.text.DecimalFormat df=new java.text.DecimalFormat("#.##"); //仅保留小数点后两位
avg = num/array.length;
System.out.println("大于输入正数的平均值 "+df.format(avg)+" 的数有:");
for (int i=0;i
if(avg
System.out.print(array[i]+" ");
}
}
}