A cópia do código é a seguinte:
importar java.util.hashmap;
importar java.util.map;
classe pública figureandchinese2util {
// cache todos os números
mapa estático privado <caractere, caractere> map = novo hashmap <caractere, caractere> (
10);
estático {
map.put ('1', '1');
map.put ('2', '2');
map.put ('3', 'três');
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');
}
estático char [] modo = novo char [] {'ela', '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]));
} outro
m0 (sb, 0, sbf);
sbf.append ("inteiro");
System.out.println (SBF);
}
/***
* Corte a corda
*
* @param sb
*/
public static void M0 (String SB, Int Type, StringBuffer SBF) {
int len = sb.length ();
int b = 0;
tipo ++;
if (len> = 4) {
b = len - 4;
sbf.insert (0, m1 (sb.substring (b), tipo));
M0 (sb.substring (0, b), tipo, sbf);
} else if (len> 0)
sbf.insert (0, m1 (sb, tipo));
if ('zero' == sbf.charat (0))
sbf.deleteCharat (0);
}
/***
* tratar
*
* @param sb
*/
public static stringbuffer m1 (string sb, int tipo) {
Stringbuffer sbf = new StringBuffer (sb);
switch (tipo) {
Caso 1:
sbf.append ("círculo");
quebrar;
Caso 2:
sbf.append ("dez mil");
quebrar;
Caso 3:
sbf.append ("中");
quebrar;
padrão:
quebrar;
}
// Iniciar a atribuição
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));
se (i! = 0)
sbf.insert (i, modo [b]);
b ++;
}
for (int i = 0; i <sbf.length (); i ++) {
t = sbf.charat (i);
if (t == 'zero') {
t = sbf.charat (i + 1);
if ('círculo'! = t && 'milhão'! = t && 'milhão'! = t)
sbf.deleteCharat (i + 1);
outro
sbf.deleteCharat (i);
se (i! = 0)
if (sbf.charat (i - 1) == 'zero') {
sbf.deleteCharat (i - 1);
eu--;
}
}
}
if (sbf.length () == 1) {
if ('círculo'! = sbf.charat (0))
sbf.setLength (0);
}
retornar 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 ()) {
Caso 1:
sb.append ("ângulo");
quebrar;
Caso 2:
sb.setcharat (1, map.get (sb.charat (1)));
if (sb.charat (0)! = 'zero')
sb.insert (1, 'ângulo');
sb.append ("Score");
quebrar;
padrão:
quebrar;
}
}
retornar sb;
}
public static void main (string [] args) {
String s = "44444444441.23";
String s1 = "1";
String S2 = "1000000000.01";
String S3 = "101010002.11";
EM);
m (S1);
m (s2);
m (S3);
}
}