|
import java.util.Scanner;
public class NumToChinese {
public static void ToChinese (Long num) {
String n [] = {"Zero", "One", "Two", "Three", "Wu", "Wu", "Lu", "柒", "捌", "Jiu"};
String unit [] = {"", "Pickup", "Bai", "仟"};
String unit1 [] = {"100 million", "Ten thousand"};
StringBuilder chi = new StringBuilder ();
for (int i = 0; i <num.toString (). length (); i ++) {
chi.append (n [Integer.parseInt (String.valueOf (num.toString (). charAt (i)))]);
chi.append (unit [(num.toString (). length ()-i-1)% 4]);
if ((num.toString (). length ()-i)% 4 == 1)
{
chi.append (unit1 [(int) Math.floor ((double) (num.toString (). length ()-i) / 4)% 2]);
}
}
String ch = chi.toString ();
ch = ch.replaceAll ("零 千", "zero");
ch = ch.replaceAll ("Zero Bai", "Zero");
ch = ch.replaceAll ("zero pick", "zero");
while (ch.indexOf ("Zero Zero")> 0)
{
ch = ch.replaceAll ("zero zero", "zero");
}
ch = ch.replaceAll ("Zero Ten Thousand", "Ten Thousand");
ch = ch.replaceAll ("Zero Billion", "Billion");
ch = ch.replaceAll ("Billion", "Billion");
System.out.println (ch.substring (0, ch.length ()-1));
}
public static void main (String [] args) {
Scanner in = new Scanner (System.in);
while (true)
{
long num = in.nextLong ();
if (num == 0)
{
System.exit (0);
}
ToChinese (new Long (num));
}
}
} |
|