pat1002. Write the number (20)

Read in a natural number n, calculate the sum of its digits, and write each digit of the sum in Chinese pinyin.

Input format: Each test input contains 1 test case, that is, the value of the natural number n is given. Here n is guaranteed to be less than 10 100 .

Output format: output each digit of the sum of the digits of n in one line, there is 1 space between the pinyin numbers, but there is no space after the last pinyin number in a line.

Input sample:
1234567890987654321123456789
Sample output:
yi san wu
--------------------------------------------
package text; 


import java.util.Scanner; 


public class Main { public static void main(String[] args) {
 Scanner scanner =new Scanner(System.in);
 String num=scanner.next(); //Input number Too long, exceeding the long type, use string to accept
 int sum=0;
 String str="";
 for(int i=0;i<num.length();i++){
 String a=num.substring(i, i +1); //Card out each digit and convert it into a number
 sum=sum+Integer.parseInt(a); //Find the sum of each digit }
 while(sum!=0){
 int i=sum%10;
 switch(i){
 case 0:str="ling "+str;break; //The sum of each person, converted into the pinyin display of each digit
 case 1:str="yi "+str;break;
 case 2:str= "er "+str;break;
 case 3:str="san "+str;break;
 case 4:str="si "+str;break;
case 5:str="wu "+str;break;

																	
			


				
																													case 6:str="liu "+str;break;
 			case 7:str="qi "+str;break;
 			case 8:str="ba "+str;break;
 			case 9:str="jiu "+str; break;
 			}
 			sum=sum/10;
 }
 str=str.substring(0,str.length()-1); //No spaces after the last digit Pinyin
 System.out.println(str);
 } 
}			
							
		
	
 
 



Guess you like

Origin blog.csdn.net/zhzh980/article/details/72724093