PAT乙级 写出这个数java答案

import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Main main1 = new Main();
    Scanner in=new Scanner(System.in);
    String a=in.next();
    int sum=0;
    for(int i=0;i<a.length();i++){
      int b=Integer.parseInt(String.valueOf(a.charAt(i)));
      sum=sum+b;
    }
    String sumString=String.valueOf(sum);
    for(int j=0;j<sumString.length();j++){
      char c=sumString.charAt(j);
      if(j==sumString.length()-1){
        main1.speakNum(c,1);
      }else{
        main1.speakNum(c,0);
      }
    }
  }
  public void speakNum(char num,int type){
    if(type==0){
      switch(num){
      case '0':
        System.out.print("ling ");
        break;
      case '1':
        System.out.print("yi ");
        break;
      case '2':
        System.out.print("er ");
        break;
      case '3':
        System.out.print("san ");
        break;
      case '4':
        System.out.print("si ");
        break;
      case '5':
        System.out.print("wu ");
        break;
      case '6':
        System.out.print("liu ");
        break;
      case '7':
        System.out.print("qi ");
        break;
      case '8':
        System.out.print("ba ");
        break;
      case '9':
        System.out.print("jiu ");
        break;
      }
    }else{
      switch(num){
      case '0':
        System.out.print("ling");
        break;
      case '1':
        System.out.print("yi");
        break;
      case '2':
        System.out.print("er");
        break;
      case '3':
        System.out.print("san");
        break;
      case '4':
        System.out.print("si");
        break;
      case '5':
        System.out.print("wu");
        break;
      case '6':
        System.out.print("liu");
        break;
      case '7':
        System.out.print("qi");
        break;
      case '8':
        System.out.print("ba");
        break;
      case '9':
        System.out.print("jiu");
        break;
      }
    }
  }
}
全部评论

相关推荐

10-15 16:27
门头沟学院 C++
LeoMoon:建议问一下是不是你给他付钱😅😅
点赞 评论 收藏
分享
11-02 09:49
已编辑
货拉拉_测试(实习员工)
热爱生活的仰泳鲈鱼求你们别卷了:没事楼主,有反转查看图片
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务