See an article today: "Original link"
The title is "read in a number n, calculate the sum of their numbers, write in Hanyu Pinyin and each digit", is implemented in C language. Since I am currently learning Java, I would like to use Java to achieve the next.
Input format: Each test input contains 1 test cases, which gives the value of the natural number N. This guarantees that n is less than 10100.
Output format: output n in one line each digit of the sum of the number of digits, there are 1 spaces between the phonetic numerals, but there is no space after the last phonetic number in a row.
import java.io.bufferedreader;import java.io.ioexception;import java.io.inputstreamreader; Public class int_to_string { public static void main ( String[] args) { BufferedReader br = New bufferedreader (New inputstreamreader (system.in)); try { int sum = 0 ; string str = br.readline (); //resolves a problem that exceeds the int type. The string is assembled by the number of characters. char[] ch = Str.tochararray (); for (int i = 0 ; i < ch.length ; i ++) { //sum sum += new integer ("" +ch[i]). IntValue (); } system.out.println (Print_f (sum)); } catch (ioexception e) { e.printstacktrace (); } finally { try { if (br != null) { &nbSp; br.close (); } } catch (ioexception e) { e.printstacktrace (); } } } public static string print_f (int sum) { int k = 1; int m = sum; String str = ""; while (m >= &NBSP;10) { k *= 10 ; m /= 10; } while (k != 0) { str += int_to_string (sum / k) + " "; sum %= k; k /= 10; } return str.substring (0, str.length ()-1) ; } //Conversion public static string int_to_string (int n) { string ss = ""; switch (n) { case 0: ss = "Ling"; break; case 1: ss = "Yi"; break; case 2: ss = "ER"; break; case 3: ss = "San"; break; case 4: ss = "Si"; break; case 5: ss = "WU"; break; case 6: ss = "Liu"; break; case 7: ss = "Qi"; break; case 8: ss = "BA"; break; case 9: ss = "JIU"; break; default: break; } return ss; }}
This article is from the "Orange Growth Record" blog, be sure to keep this source http://azhome.blog.51cto.com/9306775/1546766
The Java implementation reads in a number n, calculates the sum of its numbers, and writes each digit in Hanyu Pinyin.