A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 911288373 中级黑马   /  2013-1-1 16:26  /  1291 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

public class Test10 {

public static String[] cn={"仟","佰","拾","亿","仟","佰","拾","万","仟","佰","拾","圆整"};
public static String[] number={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
public static String getString(long n)
{
String money=""+n;
if(money.length()>cn.length)
return "钱太多";
String str="";
for(long i=0;i<money.length();i++)
str+=number[Integer.parseInt(""+money.charAt(i))]+cn[cn.length-money.length()+i];
return str;
}
public static void main(String[] args) {
System.out.print(getString(101000001010));
}
}

帮忙优化下吧  101000001010  把它转了。  

2 个回复

倒序浏览
101000001010  这个数代表int 型 越界了,

末尾应该添加一个L或小写l。
回复 使用道具 举报
楼主把你的程序改成下面这样试试,道先是传入参数啦,你传整型数默认是int类型的,你要传个long型数进去就要加个大写L或小写l在数的后面,另外long类开支是没有charAt()方法的·,所以将i改成int类型··致于功能方面·先不想了,我该说我是来抢加分机会的吗··
public class Test {
        public static String[] cn={"仟亿","佰亿","拾亿","亿","仟万","佰万","拾万","万","仟","佰","拾","圆整"};
        public static String[] number={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        public static String getString(long n)
         {
         String money=""+n;
         if(money.length()>cn.length)
         return "钱太多";
        String str="";
         for(int i=0;i<money.length();i++)
         str+=number[Integer.parseInt(""+money.charAt(i))]+cn[cn.length-money.length()+i];
         return str;
         }
         public static void main(String[] args) {
         System.out.print(getString(101000001010l));
         }
}
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马