|
public class Rectangle
{
public static String daxie (int sum)
{
String [] n = new String [10];
n [0] = "";
n [1] = "One";
n [2] = "贰";
n [3] = "三";
n [4] = "肆";
n [5] = "伍";
n [6] = "陆";
n [7] = "柒";
n [8] = "捌";
n [9] = "玖";
String [] d = new String [10];
d [0] = "";
d [1] = "pick up";
d [2] = "百";
d [3] = "仟";
String [] e = new String [10];
e [0] = "万";
e [1] = "billion";
// Calculate the number of digits
// int wei = (int) Math.floor
// (
// Math.log10 ((double) sum)
//) +1;
String old = "" + sum;
int wei = (old) .length ();
System.out.println ("Calculated number of digits ==" + wei);
ArrayList str = new ArrayList ();
int digit = 0;
int digit1 = 0;
for (int i = wei-1; i> = 0; i-) {
if (! "0" .equals ("" + old.charAt (i))) {
str.add (0, d [digit]);
str.add (0, n [Integer.parseInt ("" + old.charAt (i))]);
}
digit ++;
if (digit == 4) {
digit = 0;
str.add (0, e [digit1]);
digit1 ++;
}
}
System.out.println (str);
return str.toString ();
}
public static void main (String [] args)
{
System.out.println (daxie (100212334));
}
}
Calculate the number of digits == 9
[One, billion, ten, ten, one, ten, ten, ten, three, three hundred, three, ten, four,]
[One, billion, ten, ten, one, ten, ten, ten, three, three hundred, three, ten, four,]
See for yourself |
|