CopyCode The Code is as follows: Import java. util. arraylist;
Import java. util. List;
Public class rmbconverter2 implements irmbconverter {
Private Static final string [] RMB _number = {"zero", "one", "two", "three", "Si", "Wu", "Lu ", "identifier", "identifier", "identifier "};
Private Static final string [] RMB _attr = {"Yuan", "Ten", "Hundred ", "Category", "million", "10", "category", "category", "", "10", "category", "category "};
Private Static final string [] RMB _fen = {"points", "Angles "};
@ Override
Public String change2rmb (double counts ){
Stringbuffer rsbuf = new stringbuffer ();
If (counts = 0l ){
Return "zero ";
}
If (counts <0)
Rsbuf. append ("negative ");
String Zheng = strconverse (string. valueof (long) Counts ));
String Xiao = strconverse (string. valueof (math. Round (counts-(long) Counts) * 100 )));
Char [] zhengarray = Zheng. tochararray ();
Char [] xiaoarray = Xiao. tochararray ();
Int zlength = zhengarray. length;
Int xlength = xiaoarray. length;
List <string> zhenglist = new arraylist <string> ();
For (INT I = 0; I <zlength; I ++ ){
Int value = integer. parseint ("" + zhengarray [I]);
If (value = 0 & (I! = 4) & (I! = 8) & I! = 0 ){
Zhenglist. Add (RMB _number [value]);
} Else {
Zhenglist. Add (RMB _number [value] +
RMB _attr [I]);
}
}
For (INT I = zhenglist. Size ()-1; I> = 0; I --){
Rsbuf. append (zhenglist. Get (I ));
}
For (INT I = 0; I <xlength; I ++ ){
Int value = integer. parseint ("" + xiaoarray [I]);
If (value> 0 ){
Rsbuf. append (RMB _number [value])
. Append (RMB _fen [xLength-i-1]);
}
}
String rs = rsbuf. tostring ();
Rs = Rs. replaceall ("Zero +", "zero ");
Rs = Rs. replaceall ("0 RMB", "RMB ");
Rs = Rs. replaceall ("0 thousand ");
Rs = Rs. replaceall ("0 billion ");
Rs = Rs. replaceall ("hundreds of millions", "hundreds of millions ");
Return Rs;
}
Private string strconverse (string Str ){
Stringbuffer rs = new stringbuffer ();
Char [] strarray = Str. tochararray ();
For (INT I = Str. Length ()-1; I> = 0; I --){
Rs. append (strarray [I]);
}
Return Rs. tostring ();
}
Public static void main (string ARGs []) {
Rmbconverter2 C2 = new rmbconverter2 ();
System. Out. println (c2.change2rmb (2001004.10 ));
System. Out. println (c2.change2rmb (2000000.10 ));
System. Out. println (c2.change2rmb (0l ));
System. Out. println (c2.change2rmb (commandid 0000000l ));
}
}