package com.itheima;
/* 金额转换,阿拉伯数字转换成中国传统形式。例如:101000001010
* 转换为 壹仟零壹拾亿零壹仟零壹拾圆整
*/
public class Text10 {
/**
* @param args
*/
public static void main(String[] args) {
String str ="18941000";
//拿了字符串反转的类进行了一下反转
STRcaozuo3 Sc =new STRcaozuo3();
//反转之后再传进去
String Sb =Sc.Str1(str);
Strzhuan.Zhuan(Sb);
}
}
class Strzhuan{
@SuppressWarnings("null")
public static String Zhuan(String s){
String [] Str =new String []{"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
String [] Str1 =new String[]{"","拾","佰","仟","万","拾万","佰万","仟万","亿","拾亿","佰亿","仟亿","万亿"};
StringBuffer Strbf =new StringBuffer("");
String Ss =null;
String S1 =null;
String oid =null;
for(int i =(s.length()-1);i<s.length()&&i!=-1;i--){
//把拿到的字符转成相应的数字
char cr =s.charAt(i);
int P =Character.getNumericValue(cr);
Ss = (Str[P]);
//为什么空指针 前面遇到一个空指针麻烦了。已解决
if(Ss!=oid){
Strbf.append(Ss);
}
S1=Str1[i];
if(P!=0){
Strbf.append(S1);
}
oid =Ss;
}
Strbf.append("圆整");
String S3 =new String(Strbf);
System.out.println(S3);
return Ss;
}
}
class STRcaozuo3{
//字符串缓冲区,用来追加每次循环遍历出来的字符串
StringBuffer Strbf =new StringBuffer();
public String Str1(String str){
//从大的指标从下走,并且指标不为-1,把拿到的值装进去缓冲区
for(int I=(str.length()-1);I<str.length()&&I>-1;I--){
Strbf.append(str.charAt(I));
}
//再把处理好的数据装回String并返回
String is =new String(Strbf);
return is;
}
}
看看这个代码中的,输入壹佰的话,是“壹佰零圆整”这个bug怎么搞,还有其他bug |