Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 164661 | Accepted: 61136 |
Description java
Input ide
Output this
Sample Input spa
100.00 489.12 12454.12 1234.10 823.05 109.20 5.27 1542.25 839.18 83.99 1295.01 1.75
Sample Output rest
$1581.42
Source code
如下代碼能夠經過。 ip
import java.util.*; import java.text.*; public class Main { public static void main(String[] args){ Scanner cin = new Scanner(System.in); float value = 0; float temp = 0; for(int i=0; i<12; i++){ temp = Float.valueOf(cin.nextLine()).floatValue(); value += temp; } cin.close(); value = value / 12; DecimalFormat df = new DecimalFormat(".00"); String str = df.format(value); System.out.println("$" + str); } }
於此同時,個人BigDecimal的版本老是被報告Runtime Error。不知何故。 ci
//import java.io.BufferedInputStream; import java.math.BigDecimal; import java.util.Scanner; public class Main { public static void main(String[] args) { //Scanner in = new Scanner(new BufferedInputStream(System.in)); Scanner in = new Scanner(System.in); String str = null; BigDecimal total = new BigDecimal(0); for(int i=0; i<12; i++){ str = in.nextLine(); total = total.add(new BigDecimal(str)); } in.close(); BigDecimal average = total.divide(new BigDecimal(12)); System.out.println("$" + average.toString()); } }