| 做了好久,发现思路不对,太坑了,我i这种做法通过字符串长度分情况那就太麻烦了,代码太长了,中文读数字有很多读法,我想可不可以把中文字符串用'百''十'切割,这样应该可以,有时间再做做,希望老师能给点辛苦分 
 
 复制代码import java.io.*;
class Demo
{
        public static void main(String[] args)throws Exception
        {
                System.out.println(getInt());
        }
        public static int getInt()throws Exception
        {
                System.out.println("请出入零到九九九之间的中文");
                BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
                String ss=bf.readLine();
                int sum=0;
                int num=0;
                int i=0;
                int len= ss.length();
                if (len<5&&len>=3)
                        i=3;
                if(len<3&&len>=1)
                        i=1;
                                for(int x=0;x<i;x+=2)
                                {
                                        char ch = ss.charAt(x);
                                        switch (ch)
                                        {
                                        case '一' : num=1*(int)Math.pow(10,(2-x/2));
                                                break;
                                        case '二' : num=2*(int)Math.pow(10,(2-x/2));
                                                break;
                                        case '三' : num=3*(int)Math.pow(10,(2-x/2));
                                                break;
                                        case '四' : num=4*(int)Math.pow(10,(2-x/2));
                                                break;
                                        case '五' : num=5*(int)Math.pow(10,(2-x/2));
                                                break;
                                        case '六' : num=6*(int)Math.pow(10,(2-x/2));
                                                break;
                                        case '七' : num=7*(int)Math.pow(10,(2-x/2));
                                                break;
                                        case '八' : num=8*(int)Math.pow(10,(2-x/2));
                                                break;
                                        case '九' : num=9*(int)Math.pow(10,(2-x/2));
                                                break;
                                        case '零' : num=0*(int)Math.pow(10,(2-x/2));
                                                break;
                                                default:System.out.print("输入错误");
                                        
                                        }
                                        sum+=num;
                                }
                                return sum;
        }
        
}
 |