首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

银行结算系统其中的一格小疑点

2012-01-20 
银行结算系统其中的一格小问题在银行结算系统中,有个任务是将阿拉伯数字转换成汉字,如 123456 转换成

银行结算系统其中的一格小问题
在银行结算系统中,有个任务是将阿拉伯数字转换成汉字,如 "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) {


// TODO 自动生成方法存根
double inputvalue = 1234567890123.312030;
if(inputvalue == 0) {
System.out.print( "零 ");
return;
}
String stringvalue,sintvalue,sdecvalue;
DecimalFormat ss = new DecimalFormat( "0.00 ");
stringvalue = ss.format(inputvalue);
int decbit;
decbit = stringvalue.indexOf( ". ");
if(decbit == 0){
sintvalue = stringvalue;
sdecvalue = " ";
}else{
sintvalue = stringvalue.substring(0,decbit);
sdecvalue = stringvalue.substring(decbit + 1);
}
String chesenumunit[] = { " ", "壹 ", "贰 ", "叁 ", "肆 ", "伍 ", "陆 ", "柒 ", "捌 ", "玖 "};
helloworld hwtochn = new helloworld();
//处理整数
String schar,sreversed,schnintvalue= " ",schndecvalue= " ";
int ibit;
StringBuffer s=new StringBuffer(sintvalue);
sreversed = s.reverse().toString();
for(int i= 0;i <sreversed.length();i++)
{
schar = sreversed.substring(i, i+1);
ibit = Integer.parseInt(schar);
schnintvalue = chesenumunit[ibit] + hwtochn.GetUnit(i) +schnintvalue;
}

//清除多余的单位
String slist = "拾佰仟万亿 ";
for(int i= schnintvalue.length()-1;i> =0;i--)
{
schar = schnintvalue.substring(i, i+1);
if(slist.indexOf(schar)> =0)
{
for(int j = i-1;j> =0;j--)
{
String shighchar;
shighchar = schnintvalue.substring(j, j+1);
if(slist.indexOf(shighchar) <0)
{
break;
}
else if(slist.indexOf(shighchar,slist.indexOf(schar)+1)> =0)
{
schnintvalue = schnintvalue.substring(0,i)+schnintvalue.substring(i+1);
break;
}

}
}
}
schnintvalue = schnintvalue + "圆 ";

//处理小数
ibit = Integer.parseInt(sdecvalue.substring(0,1));
if (ibit > 0) schndecvalue = chesenumunit[ibit] + "角 ";
ibit = Integer.parseInt(sdecvalue.substring(1,2));
if (ibit > 0) schndecvalue = schndecvalue + chesenumunit[ibit] + "分 ";
String schnnum;
schnnum = schnintvalue + schndecvalue+ "整 ";
System.out.print(stringvalue+schnnum);

}
public String GetUnit(int num) {//取单位 非零数字按位数取单位
int level;
level = num%4;
switch(level) {
case 0:
if(num == 0)
return " ";
else
if(num%8 == 0) return "亿 "; else return "万 ";
case 1:
return "拾 ";
case 2:
return "佰 ";
case 3:
return "仟 ";
default:
return " ";
}
}

}
//这是我写的,自己去看吧,应该没写错吧
[解决办法]
应该不难的, 每四位一个循环, 每位初10的n次幂取余转换并且加十,百,千,一个变量存储是第几个四位,第二个加万,第三个加亿。。。遇0就是零,应该就没问题了

热点排行