zoukankan      html  css  js  c++  java
  • 阿拉伯数字转中国的数字

    import java.util.*;
    class Work7
    {
        public static void main(String[] args)
        {
              System.out.println("请输入一个数字");
              String[] str = new String[]{"拾","百","千","万","十","百","千","亿","十","百","千"};
              Scanner sac = new Scanner(System.in);
              
              int sum = sac.nextInt();
             int sum2=sum;
                  int a=0;
            for (int i = 0 ; i<32 ;i++ )
            {
                if(sum/10>0){
                    sum=sum/10;
                    a++;
                }else{
                
                    break;
                }
            }
            if (sum2<10)
            {
                 int k =sum;
                   String ss =  zifu(k);
                System.out.print(ss+"元整");

            }else{
                
                 for (int i = a ;i>=0 ;i-- )
            {

                     if (i==0)
                     {
                         int c = sum2%10;
                          String ss1 =  zifu(c);
                         System.out.print(ss1+"元整");


                     }else if(i>0){
                        int new1=(int)Math.pow(   10,    i);
                            
                            //参数说明:m为要求方的数,n为次方数
                    
                          int b = sum2/new1%10;
                            String ss2 =  zifu(b);
                            if (b==0)
                            {   
                                    //System.out.print(a+""+i);
                                    if (i==4||i==8)
                                    {
                                      if (i==8)
                                      {
                                     System.out.print("亿"+ss2);
                                    
                                      }else{
                                        System.out.print("万"+ss2);
                                      }
                                    }
                                    else{
                                    System.out.print(ss2);
                                    }

                            
                                
                            }else{
                                
                                
                                System.out.print(ss2+""+str[i-1]);
                                
                                
                                    
                               
                            }
                        
                          
                    
                     }
                  


            }
            
            
            }

            
        }
        public static String zifu(int a){
              String str =" ";
         switch (a)
          {
          case 1:
         
               str ="一";
          break;
          case 2:
         
              str ="二";
          break;
          case 3:
         
             str ="三";
          break;
          case 4:
         
              str ="四";
          break;
           case 5:
         
               str ="五";
          break;
           case 6:
         
               str ="六";
          break;
           case 7:
         
               str ="七";
          break;
           case 8:
         
              str ="八";
          break;
           case 9:
         
             str ="九";
          break;
          case 0:
         
             str ="零";
          break;
        
            default :
                break;
            

          
          }
          return str;
        
        
        }
    }

  • 相关阅读:
    一天时间用python写门语言
    360以安全之名做搜索,可信,还是欺世盗名?
    Servicemix,Karaf和Camel
    Struts2>action 小强斋
    解决JBoss只能通过localhost(127.0.0.1)而不能通过IP访问 小强斋
    java.sql.SQLException: 关闭的连接 小强斋
    Struts2>action 小强斋
    flex>MXML语法 小强斋
    jsp>tomcat配置虚拟目录 小强斋
    解决JBoss只能通过localhost(127.0.0.1)而不能通过IP访问 小强斋
  • 原文地址:https://www.cnblogs.com/zzzhangzheng/p/6100877.html
Copyright © 2011-2022 走看看