Die Codekopie lautet wie folgt:
import Java.util.hashMap;
import Java.util.map;
öffentliche Klasse Figureandchinese2util {
// alle Zahlen zwischenstrichen
private statische Karte <Charakter, Zeichen> map = new Hashmap <Zeichen, Zeichen> (
10);
statisch {
map.put ('1', '1');
map.put ('2', '2');
map.put ('3', 'drei');
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 [] modus = new char [] {'sie', '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]));
} anders
M0 (SB, 0, SBF);
sbf.append ("ganz");
System.out.println (SBF);
}
/***
* Schnitt String
*
* @param sb
*/
public static void M0 (String SB, Int Type, StringBuffer SBF) {
int len = sb.length ();
int b = 0;
Typ ++;
if (len> = 4) {
B = Len - 4;
sbf.insert (0, m1 (sb.substring (b), Typ));
M0 (SB.Substring (0, B), Typ, SBF);
} else if (len> 0)
sbf.insert (0, M1 (SB, Typ));
if ('Zero' == sbf.charat (0))
sbf.deletecharat (0);
}
/***
* bewältigen
*
* @param sb
*/
public static StringBuffer M1 (String SB, Int Type) {
StringBuffer sbf = new StringBuffer (SB);
Switch (Typ) {
Fall 1:
sbf.Append ("Kreis");
brechen;
Fall 2:
sbf.append ("zehntausend");
brechen;
Fall 3:
sbf.append ("中");
brechen;
Standard:
brechen;
}
// Zuordnung starten
int b = 0;
char t = 0;
für (int i = sbf.length ()-2; i> = 0; i--) {
t = sbf.charat (i);
sbf.setcharat (i, map.get (t));
if (i! = 0)
sbf.insert (i, modus [b]);
B ++;
}
für (int i = 0; i <sbf.length (); i ++) {
t = sbf.charat (i);
if (t == 'Zero') {
t = sbf.charat (i + 1);
if ('Circle'! = T && 'Millionen'! = T && 'Millionen'! = T)
sbf.deletecharat (i + 1);
anders
sbf.deletecharat (i);
if (i! = 0)
if (sbf.charat (i - 1) == 'Zero') {
sbf.deletecharat (i - 1);
ich--;
}
}
}
if (sbf.length () == 1) {
if ('circle'! = sbf.charat (0))
sbf.setLength (0);
}
Return 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 ()) {
Fall 1:
Sb.Append ("Angle");
brechen;
Fall 2:
sb.setcharat (1, map.get (sb.charat (1)));
if (sb.charat (0)! = 'Zero')
sb.insert (1, 'Winkel');
Sb.Append ("Score");
brechen;
Standard:
brechen;
}
}
Return SB;
}
public static void main (String [] args) {
String S = "44444444441.23";
String S1 = "1";
String S2 = "1000000000.01";
String S3 = "101010002.11";
MS);
M (S1);
M (S2);
M (S3);
}
}