[PKU] P1004: Financial Management
Description
Larry
graduated this year and finally has a job. He’s making a lot of money,
but somehow never seems to have enough. Larry has decided that he needs
to grab hold of his financial portfolio and solve his financing
problems. The first step is to figure out what’s been going on with his
money. Larry has his bank account statements and wants to see how much
money he has. Help Larry by writing a program to take his closing
balance from each of the past twelve months and calculate his average
account balance.
graduated this year and finally has a job. He’s making a lot of money,
but somehow never seems to have enough. Larry has decided that he needs
to grab hold of his financial portfolio and solve his financing
problems. The first step is to figure out what’s been going on with his
money. Larry has his bank account statements and wants to see how much
money he has. Help Larry by writing a program to take his closing
balance from each of the past twelve months and calculate his average
account balance.
Input
The
input will be twelve lines. Each line will contain the closing balance
of his bank account for a particular month. Each number will be
positive and displayed to the penny. No dollar sign will be included.
input will be twelve lines. Each line will contain the closing balance
of his bank account for a particular month. Each number will be
positive and displayed to the penny. No dollar sign will be included.
Output
The
output will be a single number, the average (mean) of the closing
balances for the twelve months. It will be rounded to the nearest
penny, preceded immediately by a dollar sign, and followed by the
end-of-line. There will be no other spaces or characters in the output.
output will be a single number, the average (mean) of the closing
balances for the twelve months. It will be rounded to the nearest
penny, preceded immediately by a dollar sign, and followed by the
end-of-line. There will be no other spaces or characters in the output.
Sample Input
1 |
100.00<br />489.12<br />12454.12<br />1234.10<br />823.05<br />109.20<br />5.27<br />1542.25<br />839.18<br />83.99<br />1295.01<br />1.75 |
Sample Output
1 |
$1581.42 |
Source
Solution:
[#M_ more.. | less.. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import java.util.Scanner; public class P1004 { public static void main(String[] args) { double total = 0; Scanner sc = new Scanner(System.in); for(int i=0; i<12; i++) { total += Double.parseDouble(sc.nextLine()); } System.out.printf("$%.2f\n",total/12); } } |