题解 | #求平均数#
求平均数
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...... int sum=0; int count=0; double avg=0.0; while(scan.hasNext()) { int n=scan.nextInt(); if(n<0) { break; } count++; sum+=n; } avg=(double)sum/count; System.out.println(String.format("%.2f",avg)); } }