POJ1004

作者: Shiki | 来源:发表于2014-08-21 15:58 被阅读0次

问题描述###

无~


难点###

错了一次,输出格式问题。题目本身没有难度。


代码实现###

package poj; import java.text.DecimalFormat; import java.util.Scanner; public class Poj1004 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double sum = 0.0; for(int i = 0 ; i < 12 ; i ++){ sum += sc.nextDouble(); } DecimalFormat df=new DecimalFormat(); df.setMaximumFractionDigits(2); df.setMinimumFractionDigits(2); System.out.println("$"+df.format(sum/12).replaceAll(",", "")); System.out.println("$"+df.format(sum/12)); sc.close(); } }


需要注意的是用DecimalFormat会自动的出现逗号~
test data:

15585414.1
145411445.2
5511.5
511.52
25
25514
5541
551
1235
2635.2
213265.555
1.235458485

Output:

$13437637.53
$13,437,637.53

相关文章

  • POJ1004

    问题描述### 无~ 难点### 错了一次,输出格式问题。题目本身没有难度。 代码实现### package po...

网友评论

      本文标题:POJ1004

      本文链接:https://www.haomeiwen.com/subject/vsaetttx.html