2010-11-29 01:10:56import java.util.*; import tools.*; class transNumber { static private String[] _1_19num=new String[]{" one"," two"," three"," four"," five"," six"," seven"," eight"," nine" ," ten"," eleven"," twelve"," thirteen"," fourteen"," fifteen"," sixteen"," seventeen"," eighteen"," nineteen"}; static private String[] _20_90num=new String[]{" twenty"," thirty"," forty"," fifty"," sixty"," seventy"," eighty"," ninety"}; static private String[] big=new String[]{" thousand"," million"," billion"}; public static void main(String[] args) { String num="1113240"; String[] s=insert(tranBy3bit(num)); for(int i=0;i<s.length;i++) p.rintln(s[i]); } static String[] insert(String[] s) { int length=s.length; for(int i=length;i>-1;i-=3)//insert "hundred" { if(i-3>-1) { s[i-3]+=" hundred"; } else break; } for(int i=length-1,j=0;i>-1;i-=3,j++)//insert "thousand,million,billion" { if(i-3>-1) { s[i-3]+=big[j]; } else break; } return s; } static String[] tranBy3bit(String num) { int length=num.length(); char[] cnum=num.toCharArray(); int[] inum=new int[length]; String[] tran2Str=new String[length]; for(int i=0;i<length;i++) { inum[i]=Integer.parseInt(Character.toString(cnum[i])); } for(int i=length-1;i>-1;i-=3) //step by 3 in english { if(i==-1)break; tran2Str[i]=dobit(inum[i]); if(i-1==-1)break; if(inum[i-1]==1)tran2Str[i]=""; tran2Str[i-1]=do2bit(inum[i-1],inum[i]); if(i-2==-1)break; tran2Str[i-2]=dobit(inum[i-2]); } return tran2Str; } static String dobit(int b1) { if(b1==0) { return ""; } else return _1_19num[b1-1]; } static String do2bit(int b2,int b1) { switch (b2) { case 1: { return _1_19num[b2*10+b1-1]; } case 0: return ""; default: return _20_90num[b2-2]; } } } 么有加入and!,累人,搞了4个小时!烟都抽了4根。 这几天学java还是比较有感觉的,嗯,加油,