题解 | #求平均数#
求平均数
http://www.nowcoder.com/practice/41e59cee1221424bb9291435aae79ae9
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double result;
double count=0;
int i=0;
while(scan.hasNext()){
double num=scan.nextDouble();
if(num<0){
break;
}
count+=num;
i+=1;
}
result=count/(i);
System.out.println(String.format("%.2f",result));
//write your code here......
//输出格式为:System.out.println(String.format("%.2f",avg));
}
}