国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Java試題之阿拉伯?dāng)?shù)字轉(zhuǎn)換成中文數(shù)字-數(shù)據(jù)結(jié)構(gòu)和算法-Tech-Java...
之前見過一道題覺著挺有意思
今天沒什么事就回想著做了一把 拿出來和大家一起看看
希望各位能給點(diǎn)意見 一起討論下


題目大概:
將一組阿拉伯?dāng)?shù)字轉(zhuǎn)換成中文大寫數(shù)字
52306 ==> 伍萬(wàn)貳千叁百零陸

我實(shí)現(xiàn)了將文件中的一組數(shù)字(每行為一個(gè)數(shù))
形如:

Java代碼
  1. 25364  
  2. 466932300  
  3. 12350006  
  4. 100000  
  5. 66699553001  

這樣的文件中的數(shù)字全轉(zhuǎn)換成中文大寫數(shù)字


只是算法沒有架構(gòu)設(shè)計(jì)的成分
可以自定義一個(gè)輸入文件既可運(yùn)行
代碼如下(源文件見附件):

Java代碼
  1. import java.io.BufferedReader;   
  2. import java.io.FileReader;   
  3.   
  4. public class Numeric2ChineseStr   
  5. {   
  6.        
  7.     public static void main(String[] args)   
  8.         throws Exception   
  9.     {   
  10.         String fileName = "c:\\input.txt";   
  11.            
  12.         // 單位數(shù)組   
  13.         String[] units = new String[] {"十""百""千""萬(wàn)""十""百""千""億"};   
  14.            
  15.         // 中文大寫數(shù)字?jǐn)?shù)組   
  16.         String[] numeric = new String[] {"零""壹""貳""叁""肆""伍""陸""柒""捌""玖"};   
  17.            
  18.         // 讀文件   
  19.         BufferedReader br = new BufferedReader(new FileReader(fileName));   
  20.         String temp = null;   
  21.         temp = br.readLine();   
  22.         String res = "";   
  23.            
  24.         while (null != temp)   
  25.         {   
  26.             // 遍歷一行中所有數(shù)字   
  27.             for (int k = -1; temp.length() > 0; k++)   
  28.             {   
  29.                 // 解析最后一位   
  30.                 int j = Integer.parseInt(temp.substring(temp.length() - 1, temp.length()));   
  31.                 String rtemp = numeric[j];   
  32.                    
  33.                 // 數(shù)值不是0且不是個(gè)位 或者是萬(wàn)位或者是億位 則去取單位   
  34.                 if (j != 0 && k != -1 || k % 8 == 3 || k % 8 == 7)   
  35.                 {   
  36.                     rtemp += units[k % 8];   
  37.                 }   
  38.                    
  39.                 // 拼在之前的前面   
  40.                 res = rtemp + res;   
  41.                    
  42.                 // 去除最后一位   
  43.                 temp = temp.substring(0, temp.length() - 1);   
  44.             }   
  45.                
  46.             // 去除后面連續(xù)的零零..   
  47.             while (res.endsWith(numeric[0]))   
  48.             {   
  49.                 res = res.substring(0, res.lastIndexOf(numeric[0]));   
  50.             }   
  51.                
  52.             // 將零零替換成零   
  53.             while (res.indexOf(numeric[0] + numeric[0]) != -1)   
  54.             {   
  55.                 res = res.replaceAll(numeric[0] + numeric[0], numeric[0]);   
  56.             }   
  57.                
  58.             // 將 零+某個(gè)單位 這樣的竄替換成 該單位 去掉單位前面的零   
  59.             for (int m = 1; m < units.length; m++)   
  60.             {   
  61.                 res = res.replaceAll(numeric[0] + units[m], units[m]);   
  62.             }   
  63.                
  64.             // 這里打印一下 可以改成寫文件   
  65.             System.out.println(res);   
  66.                
  67.             // 讀取下一個(gè)數(shù)   
  68.             res = "";   
  69.             temp = br.readLine();   
  70.         }   
  71.     }   
  72. }  
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
LeetCode 767. 重構(gòu)字符串
Java筆試題:兩個(gè)大數(shù)相乘
java將阿拉伯?dāng)?shù)字轉(zhuǎn)換為中文數(shù)字
537,劍指 Offer-字符串的排列
PostgreSQL 常用函數(shù)
C#實(shí)現(xiàn)將浮點(diǎn)數(shù)表示的貨幣數(shù)量以漢字大寫形式輸出的方法
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服