隨筆 - 5  文章 - 0  trackbacks - 0
          <2009年4月>
          2930311234
          567891011
          12131415161718
          19202122232425
          262728293012
          3456789

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章分類

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

           1import java.util.*;
           2import java.lang.*;
           3
           4public class FormatAmt {
           5
           6    public String amount(int dollars, int cents) {
           7    
           8        String ans = "";
           9        String dollarsStr = String.valueOf(dollars);
          10        int n = dollarsStr.length();
          11        int begin = (3 - (n % 3)) % 3;
          12        for (int i = 0, j = begin; i < n; ++i, j = (++j) % 3{
          13            if (i != 0 && j == 0{
          14                ans += ",";
          15            }

          16            ans += dollarsStr.charAt(i);
          17        }

          18        ans = "$" + ans + ".";
          19        if (cents < 10{
          20            ans += "0" + cents;
          21        }
           else {
          22            ans += cents;
          23        }

          24        return ans;
          25        
          26    }

          27
          28}
          posted on 2009-04-05 20:07 edwing 閱讀(121) 評論(0)  編輯  收藏 所屬分類: tc_exercise

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 阳城县| 嵩明县| 金阳县| 景宁| 元谋县| 孙吴县| 涞水县| 五莲县| 望都县| 吴桥县| 平原县| 北海市| 苍梧县| 淮滨县| 清镇市| 公安县| 弥渡县| 陆丰市| 昭通市| 双牌县| 莱州市| 交城县| 博乐市| 遵化市| 墨竹工卡县| 天峨县| 祁东县| 怀宁县| 杂多县| 屏南县| 巩留县| 抚宁县| 姜堰市| 威远县| 馆陶县| 郎溪县| 东明县| 富平县| 拉萨市| 凤冈县| 鹤庆县|