入门
POJ1004
题目意思是求浮点数的平均数
代码
import java.text.DecimalFormat; import java.util.Scanner; /** * Created by admin on 2017/10/25. */ public class POJ1004 { public static void main(String[] args) { Scanner in = new Scanner(System.in); double sum = 0.0; for (int i=0;i<12;i++) { sum = sum + in.nextDouble(); } sum = sum/12; DecimalFormat df = new DecimalFormat(".00");//小数2位 String string = df.format(sum); System.out.println("$"+string); } }