日期:2014-05-20  浏览次数:20676 次

银行结算系统其中的一格小问题
在银行结算系统中,有个任务是将阿拉伯数字转换成汉字,如 "123456 "转换成 "十二万三千四百五十六 ",这怎么实现???有余我是刚开始学习java,还有很多不懂,跪求各位大虾用java给我实现下,小弟先谢过了!!!

------解决方案--------------------
好像以前贴过,你找找
------解决方案--------------------
呵呵,最简单的就是查找替换,笨方法
String str= "12345678 ";
str=str.replaceAll( "1 ", "一 ");
....
....
------解决方案--------------------
http://blog.csdn.net/jianzhizg/archive/2007/01/08/1476883.aspx
------解决方案--------------------
JianZhiZG(健之) 博客里写了代码了,不过,觉得判断的方法,
也可以根据长度来判断。
1 00,00 0,000,第9位为亿,18为为亿亿。
同理推算个十百千万位,当然一样要判断零的位置
------解决方案--------------------
先判断位数,再确定零,最后替换?
------解决方案--------------------
以前有练习过,现在给你贴出来,参考参参考
import java.io.*;

public class D {

private static String [] faceVal =new String[]{ "零 ", "壹 ", "贰 ", "叁 ", "肆 ", "伍 ", "陆 ", "柒 ", "捌 ", "玖 "};
private static String[] level = new String[] { "圆 ", "拾 ", "佰 ", "仟 ", "萬 ", "亿 " };


/**
* Launch the application
* @param args
*/
public static void main(String args[]) {


while(true){
StringBuffer sb = new StringBuffer();
String str = new String( " ");
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

try{
str = bf.readLine();
if(str.equalsIgnoreCase( "quit ")){
System.exit(0);
}
for(int i = 0; i <str.length(); i++){
int face =new Integer(str.substring(i, i+1)).intValue();
//int face = Integer.valueOf(str.substring(i, i+1)).intValue();
sb.append(faceVal[face]);
}
//System.out.println(sb);

}
catch(Exception e){
e.printStackTrace();
}
String resultFace = sb.reverse().toString();
StringBuffer resultSb = new StringBuffer();
for(int i = 0; i <resultFace.length(); i++){
if(i==0){
resultSb.append(level[0]);
}
else if((i+4)%8==0){
resultSb.append(level[4]);
}
else if(i%8==0){
resultSb.append(level[5]);
}
else{
resultSb.append(level[i%4]);
}
resultSb.append(resultFace.substring(i,i+1));
}

String result = resultSb.reverse().toString();

result = result.replaceAll( "零仟 ", "零 ");
result = result.replaceAll( "零佰 ", "零 ");
result = result.replaceAll( "零拾 ", "零 ");

result = result.replaceAll( "[零]+ ", "零 ");

result = result.replaceAll( "零亿 ", "亿 ");
result = result.replaceAll( "零萬 ", "萬 ");
result = result.replaceAll( "零圆 ", "圆 ");

System.out.print(result);

System.out.println( "整 ");
}
}
}
------解决方案--------------------
import java.text.DecimalFormat;

public class helloworld {

/**
* @param args
*/
public static void main(String[] args) {