2018/12/04 PAT刷题 L1-007 念数字 java

代码:

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str=sc.next();
        sc.close();
        int len = str.length();
        String str1[] = new String[len];
        String nian[] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "qiu"};
        for(int i=0; i<len; i++) {
            str1[i]=str.charAt(i)+"";
            if(str1[i].equals("-")) {
                System.out.print("fu");
            } else {
                System.out.print(nian[Integer.parseInt(str1[i])]);
            }
            if (i>=0 && i<len-1) {
                System.out.print(" ");
            }
        }
    }
}

 

posted @ 2018-12-04 17:43  HHZZHH  阅读(370)  评论(0编辑  收藏  举报