7-25 念数字

7-25 念数字_第1张图片

import java.util.HashMap;
import java.util.Scanner;
class test25 {
   public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        HashMap<String, String> integerStringHashMap = new HashMap<>();
        integerStringHashMap.put("0","ling");integerStringHashMap.put("1","yi");integerStringHashMap.put("2","er");integerStringHashMap.put("3","san");integerStringHashMap.put("4","si");integerStringHashMap.put("5","wu");integerStringHashMap.put("6","liu");integerStringHashMap.put("7","qi");integerStringHashMap.put("8","ba");integerStringHashMap.put("9","jiu");

        Integer a=0;
        String s="";

        if (scanner.hasNextInt()) {
            a=scanner.nextInt();
        }
        scanner.close();

        if (a<0) {
         s="fu "; a=a*-1;
        }
        String str=a+"";
        for(int i=0;i<str.length();i++){
            s=s+integerStringHashMap.get(String.valueOf(str.charAt(i)));
            if (i!=str.length()-1) {
                s=s+" ";
            }else{
                s=s+",";
            }
        }

        System.out.print(s);

    }
}

你可能感兴趣的:(PAT,pat)