怎样编写一个把数字10000转成中文数字一万的程序,用java
5个回答
展开全部
编写一个把数字10000转成中文数字一万的程序,算法主要是使用字符串数组进行比较:
public class Test {
public static void test(int d) {
// String[] str = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
String[] str = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
// String ss[] = new String[] { "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿" };
String ss[] = new String[] { "个", "十", "百", "千", "万", "十", "百", "千", "亿" };
String s = String.valueOf(d);
System.out.println(s);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
String index = String.valueOf(s.charAt(i));
sb = sb.append(str[Integer.parseInt(index)]);
}
String sss = String.valueOf(sb);
int i = 0;
for (int j = sss.length(); j > 0; j--) {
sb = sb.insert(j, ss[i++]);
}
System.out.println(sb);
}
public static void main(String[] args) {
test(3213);
test(912321321);
}
}
展开全部
这个是我写的啊楼主请尊重版权。选择正版
HashMap<String, String> maps = new HashMap<String, String>();
maps.put("0", "零");
maps.put("1", "一");
maps.put("2", "二");
maps.put("3", "三");
maps.put("4", "四");
maps.put("5", "五");
maps.put("6", "六");
maps.put("7", "七");
maps.put("8", "八");
maps.put("9", "九");
String[] str = {"","十","百","千","万"};
String st = "10000";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < st.length(); i++) {
Character c = st.charAt(i);
String s = c.toString();
String hanZi = maps.get(s);
String danWei = str[st.length()-i-1];//数字后面的单位如万
if(s.equals("0")) {
sb.append(hanZi);
}else{
sb.append(hanZi+danWei);
}
}
System.out.println(sb.toString());
}
HashMap<String, String> maps = new HashMap<String, String>();
maps.put("0", "零");
maps.put("1", "一");
maps.put("2", "二");
maps.put("3", "三");
maps.put("4", "四");
maps.put("5", "五");
maps.put("6", "六");
maps.put("7", "七");
maps.put("8", "八");
maps.put("9", "九");
String[] str = {"","十","百","千","万"};
String st = "10000";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < st.length(); i++) {
Character c = st.charAt(i);
String s = c.toString();
String hanZi = maps.get(s);
String danWei = str[st.length()-i-1];//数字后面的单位如万
if(s.equals("0")) {
sb.append(hanZi);
}else{
sb.append(hanZi+danWei);
}
}
System.out.println(sb.toString());
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
HashMap<String, String> maps = new HashMap<String, String>();
maps.put("0", "零");
maps.put("1", "一");
maps.put("2", "二");
maps.put("3", "三");
maps.put("4", "四");
maps.put("5", "五");
maps.put("6", "六");
maps.put("7", "七");
maps.put("8", "八");
maps.put("9", "九");
String[] str = {"","十","百","千","万"};
String st = "10000";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < st.length(); i++) {
Character c = st.charAt(i);
String s = c.toString();
String hanZi = maps.get(s);
String danWei = str[st.length()-i-1];//数字后面的单位如万
if(s.equals("0")) {
sb.append(hanZi);
}else{
sb.append(hanZi+danWei);
}
}
System.out.println(sb.toString());
}
maps.put("0", "零");
maps.put("1", "一");
maps.put("2", "二");
maps.put("3", "三");
maps.put("4", "四");
maps.put("5", "五");
maps.put("6", "六");
maps.put("7", "七");
maps.put("8", "八");
maps.put("9", "九");
String[] str = {"","十","百","千","万"};
String st = "10000";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < st.length(); i++) {
Character c = st.charAt(i);
String s = c.toString();
String hanZi = maps.get(s);
String danWei = str[st.length()-i-1];//数字后面的单位如万
if(s.equals("0")) {
sb.append(hanZi);
}else{
sb.append(hanZi+danWei);
}
}
System.out.println(sb.toString());
}
参考资料: http://zhidao.baidu.com/question/311323120.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-08-25
展开全部
int i = 10000;
String strI = null;
if(i = 10000){
strI = "一万";
}
String strI = null;
if(i = 10000){
strI = "一万";
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
哇哇哇。。。呵呵。。看学到什么程度就怎么写!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询