1. 程式人生 > >2018/12/04 PAT刷題 L1-007 念數字 java

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(
" "); } } } }