大水大水~~~~直接求平均数!注意保留位数~~
Java代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import java.text.DecimalFormat; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner in = new Scanner(System.in); float res = 0; for(int i = 0; i < 12; i++){ float f = in.nextFloat(); res += f; } DecimalFormat df = new DecimalFormat( "0.00 "); float Result = res/12; String str = df.format(Result); System.out.println("$"+str); } } |
除非注明,饮水思源博客文章均为原创,转载请以链接形式标明本文地址