题解 | #求平均数#
求平均数
https://www.nowcoder.com/practice/41e59cee1221424bb9291435aae79ae9
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); double avg = 0; double sum = 0; int num = 0; //write your code here...... while(true){ double d = scan.nextDouble(); if(d < 0){ break; }else{ num++; sum += d; } } avg = sum / num; System.out.println(String.format("%.2f",avg)); } }