1002. Write this number
Reads a positive integer n, to calculate the sum of the digits, each digit and write Pinyin.
Input formats:
Each test comprises a test input, i.e. a natural number given value of n. Here guarantee n is less than 1.
Output formats:
Output on a single line between each one, Pinyin number n of the sum of the digits 1 spaces, but after the last row Pinyin digital with no spaces.
. 1 Import a java.util.Map; 2 Import the java.util.HashMap; . 3 Import java.util.Scanner; . 4 . 5 public class the Main { . 6 . 7 // reads a positive integer n, to calculate the sum of the digits, in Chinese Pinyin and write each digit. . 8 public static void main (String [] args) { . 9 10 Scanner INPUT = new new Scanner (the System.in); . 11 String STR = input.nextLine (); 12 is 13 is // string array transfected int 14 int [] = ARR new new int[str.length()]; 15 for(int i=0;i<str.length();i++){ 16 arr[i] = Integer.parseInt(str.substring(i,i+1)); 17 } 18 Integer sum=0; //输入整数的和 19 20 for(int j=0;j<arr.length;j++){ 21 sum += arr[j]; 22 } 23 24 //int[] arr1 = sum.toString().toCharArray()Select(s => int.Parse(s.ToString())).ToArray(); 25 String str1 = sum.toString(); //int转字符串 26 is String [] str1.split S = ( ""); // string array to String; 27 String SS = ""; // string of final output 28 29 for ( int K = 0; K <S. length; K ++ ) { 30 SS SS + Map = (S [K]) + "" ; 31 is } 32 SS ss.substring = (0, ss.length () -. 1); // remove the last character, i.e., spaces 33 is System.out.println (SS); 34 is } 35 36 Private static String Map (String STR) { // Construction of Chinese numerals corresponding to Map; 37 [ Map<String,String> map = new HashMap<String,String>(); 38 map.put("0","ling"); 39 map.put("1","yi"); 40 map.put("2","er"); 41 map.put("3","san"); 42 map.put("4","si"); 43 map.put("5","wu"); 44 map.put("6","liu"); 45 map.put("7","qi"); 46 map.put("8","ba"); 47 map.put("9","jiu"); 48 return map.get(str); 49 } 50 }