コードコピーは次のとおりです。
java.util.hashmapをインポートします。
java.util.mapをインポートします。
パブリッククラスのfigureandchinese2util {
//すべての番号をキャッシュします
プライベート静的マップ<文字、文字>マップ= new Hashmap <文字、文字>(
10);
static {
map.put( '1'、 '1');
map.put( '2'、 '2');
map.put( '3'、 '3');
map.put( '4'、 'si');
map.put( '5'、 'wu');
map.put( '6'、 'lu');
map.put( '7'、 'qi');
map.put( '8'、 '8');
map.put( '9'、 '9');
map.put( '0'、 'zero');
}
static char [] mode = new char [] {'he'、 'bai'、 'qian'};
public static void m(string sb){
stringbuffer sbf = new StringBuffer();
string [] sp = sb.split( "//。");
if(sp.length == 2){
M0(SP [0]、0、SBF);
SBF.Append(M2(SP [1]));
} それ以外
M0(SB、0、SBF);
sbf.append( "whole");
System.out.Println(SBF);
}
/***
*文字列をカットします
*
* @Param SB
*/
public static void m0(string sb、int type、stringbuffer sbf){
int len = sb.length();
int b = 0;
タイプ++;
if(len> = 4){
b = len -4;
sbf.insert(0、m1(sb.substring(b)、type));
M0(SB.Substring(0、B)、Type、SBF);
} else if(len> 0)
sbf.insert(0、m1(sb、type));
if( 'zero' == sbf.charat(0))
SBF.DELETECHARAT(0);
}
/***
* 対処する
*
* @Param SB
*/
public static stringbuffer m1(string sb、intタイプ){
StringBuffer SBF = new StringBuffer(SB);
switch(type){
ケース1:
sbf.append( "circle");
壊す;
ケース2:
sbf.append( "10000");
壊す;
ケース3:
sbf.append( "中");
壊す;
デフォルト:
壊す;
}
//割り当てを開始します
int b = 0;
char t = 0;
for(int i = sbf.length() - 2; i> = 0; i-){
t = sbf.charat(i);
sbf.setcharat(i、map.get(t));
if(i!= 0)
sbf.insert(i、mode [b]);
B ++;
}
for(int i = 0; i <sbf.length(); i ++){
t = sbf.charat(i);
if(t == 'zero'){
t = sbf.charat(i + 1);
if( 'circle'!= t && 'million'!= t && 'ミリオン'!= t)
SBF.DELETECHARAT(I + 1);
それ以外
sbf.deletecharat(i);
if(i!= 0)
if(sbf.charat(i -1)== 'zero'){
sbf.deletecharat(i -1);
私 - ;
}
}
}
if(sbf.length()== 1){
if( 'circle'!= sbf.charat(0))
sbf.setlength(0);
}
SBFを返します。
}
public static stringbuffer m2(string de){
if(de.Length()> 2)
de = de.substring(0、2);
de = de.ReplaceFirst( "00"、 "");
stringbuffer sb = new StringBuffer(de);
if(sb.length()> 0){
if(sb.charat(sb.length() - 1)== '0')
sb.deletecharat(sb.length()-1);
sb.setcharat(0、map.get(sb.charat(0)));
switch(sb.length()){
ケース1:
sb.append( "angle");
壊す;
ケース2:
sb.setcharat(1、map.get(sb.charat(1)));
if(sb.charat(0)!= 'zero')
sb.insert(1、 'angle');
sb.append( "score");
壊す;
デフォルト:
壊す;
}
}
SBを返します。
}
public static void main(string [] args){
文字列S = "444444444441.23";
文字列s1 = "1";
文字列S2 = "1000000000.01";
文字列S3 = "101010002.11";
MS);
m(s1);
m(s2);
M(S3);
}
}