PAT乙级1002

/*

  将每个数字的读音保存在一个数组中,计算出总数,用各位数字去数组中取读音即可

*/

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
String[] read = new String[]{"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
Scanner scanner = new Scanner(System.in);
String numStr = scanner.nextLine();
char[] numChar = numStr.toCharArray();
Long number = 0L;
for(char c : numChar){
number += Long.parseLong(String.valueOf(c));
}
char[] sumChar = String.valueOf(number).toCharArray();
StringBuilder result = new StringBuilder();
for(char c : sumChar){
result.append(read[Integer.parseInt(String.valueOf(c))]+" ");
}
if(result.length() > 0){
result.setLength(result.length() - 1);
}
System.out.println(result);
}

}
posted @ 2019-11-12 15:03  Carol淋  阅读(114)  评论(0编辑  收藏  举报