求高手帮忙解决一个很实用的问题

king4323210 2008-10-28 03:05:58
如果将用户从控制台输入的
52531.12
转换输出
伍万贰千伍佰叁拾壹元壹角贰分

不求算法
只求解题思路 谢谢!
...全文
117 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaolvlm 2008-10-30
  • 打赏
  • 举报
回复
把数分为整数部分和小数部分,然后写算法 一位一位取出来 配上相应的大写壹....
一头头 2008-10-30
  • 打赏
  • 举报
回复

import java.util.*;

public class Change {

/**
* @param args
*/
long e;
int FirstDigit;
int SecondDigit;
int ThirdDigit;
int FourthDigit;
int FifthDigit;
int Digit;
public Change (long e){
this.e = e;
}
public String GargeDigit(){
String a5,a4,a3,a2,a1;
Contain a = new Contain();
if(e/100000>0)
{ String g = "错误,数字必须小于十万";
return g;
}
else if (e/10000>0) {
FirstDigit = (int)e/10000;
SecondDigit = (int)((e/1000)%10);
ThirdDigit = (int)((e/100)%10);
FourthDigit = (int) ((e/10)%10);
FifthDigit = (int) ((e/1)%10);
Digit = 5;
if (FirstDigit != 0) a5 = String.valueOf(FirstDigit);
else a5= "";
if (SecondDigit != 0) a4 = String.valueOf(SecondDigit);
else a4 = "";
if (ThirdDigit != 0) a3 = String.valueOf(ThirdDigit);
else a3 = "";
if(FourthDigit != 0) a2 = String.valueOf(FourthDigit);
else a2 = "";
a1 = String.valueOf(FifthDigit);
String result = a.map2.get(a5) + a.map1.get("1") + a.map2.get(a4) + a.map1.get("2") + a.map2.get(a3) + a.map1.get("3")+ a.map2.get(a2) + a.map1.get("4") + a.map2.get(a1);
return result;
}
else return "a";
/* else if (e/1000>0) {
FirstDigit = 0;
SecondDigit = (int)e/1000;
ThirdDigit = (int)(e/100)%10;
FourthDigit = (int) ((e/10)%10);
FifthDigit = (int) ((e/1)%10);
Digit = 4;
}
else if (e/100>0) {
FirstDigit = 0;
SecondDigit = 0;
ThirdDigit =(int)e/100;
FourthDigit = (int) ((e/10)%10);
FifthDigit = (int) ((e/1)%10);
Digit =3;
}
else if (e/10>0) {
FirstDigit = 0;
SecondDigit = 0;
ThirdDigit = 0;
FourthDigit =(int)e/100;
FifthDigit = (int) ((e/1)%10);
Digit =2;
}
else if (e>0) {
FirstDigit = 0;
SecondDigit = 0;
ThirdDigit = 0;
FourthDigit = 0;
FifthDigit = (int) ((e/1)%10);
Digit =1;
}*/
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Change a = new Change(75432);
System.out.println(a.GargeDigit());
System.out.println("Digit = " + a.Digit);
System.out.println("FirstDigit = " + a.FirstDigit);
System.out.println("SecondDigit = " + a.SecondDigit);
System.out.println("ThirdDigit = " + a.ThirdDigit);
System.out.println("FourthDigit = " + a.FourthDigit);
System.out.println("FifthDigit = " + a.FifthDigit);


}

}
class Contain{
Map<String,String> map1 = new HashMap<String,String>();
Map<String,String> map2 = new HashMap<String,String>();
public Contain(){

map1.put("1", "万");
map1.put("2", "千");
map1.put("3", "百");
map1.put("4", "十");
map1.put("", "");

map2.put("1", "壹");
map2.put("2", "貳");
map2.put("3", "叁");
map2.put("4", "肆");
map2.put("5", "伍");
map2.put("6", "陆");
map2.put("7", "柒");
map2.put("8", "捌");
map2.put("9", "玖");
map2.put("0", "");

}

}

// 只能输入5位数
// 第一个问题 当50000的时候 千百十也有输出
// 第二个问题 当50001的时候 输出不对

/*

我自己写的 还有很多很多bug LZ跟我一起优化下好吗
king4323210 2008-10-28
  • 打赏
  • 举报
回复
谢谢你的思路!
不太明白!
xwguan 2008-10-28
  • 打赏
  • 举报
回复
a[]={"壹","贰","叁"...."九"}
b[]={"角","分","元"}
c[]={"拾","百","千","万","百万","千万","亿"...}
将你的数据转换成字符串,然后以.分成两部份。
king4323210 2008-10-28
  • 打赏
  • 举报
回复
步骤能再详细点吗
一步一步的
谢谢!
king4323210 2008-10-28
  • 打赏
  • 举报
回复
不好做啊!
要几个循环啊?
justinavril 2008-10-28
  • 打赏
  • 举报
回复
肯定要有个一个方法,去匹配阿拉伯数字和中文的壹...用switch.case做
然后就是取每一位的数字和他的位数了 我觉得不用拿这个数去整除什么10000啊什么的 直接拿字符串做处理 比如第5位的就是“万”

rugaoason 2008-10-28
  • 打赏
  • 举报
回复
准备2个数组
String[] a = new String[]{"分","角","元".....};
String[] b = new String[]{"十","百","千".....};

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧