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