标签:pre == private efault string sum bsp i++ []
读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10100。
输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1 空格,但一行中最后一个拼音数字后没有空格。
输入样例:
1234567890987654321123456789
输出样例:
yi san wu
package com.hone.basicalTry; import java.util.Scanner; public class Test10013nPlus1 { public static void main(String[] args) { Scanner ss = new Scanner(System.in); String strNum = ss.nextLine(); int sum = 0; for (int i = 0; i < strNum.length(); i++) { sum += strNum.charAt(i)-‘0‘; } String nums = ""+sum; for (int i = 0; i < nums.length(); i++) { if (i == 0) { print(nums.charAt(i)); }else { System.out.print(" "); print(nums.charAt(i)); } } } private static void print(char a) { switch (a) { case ‘0‘: System.out.print("ling"); break; case ‘1‘: System.out.print("yi"); break; case ‘2‘: System.out.print("er"); break; case ‘3‘: System.out.print("san"); break; case ‘4‘: System.out.print("si"); break; case ‘5‘: System.out.print("wu"); break; case ‘6‘: System.out.print("liu"); break; case ‘7‘: System.out.print("qi"); break; case ‘8‘: System.out.print("ba"); break; case ‘9‘: System.out.print("jiu"); break; default: break; } } }
标签:pre == private efault string sum bsp i++ []
原文地址:http://www.cnblogs.com/xiaxj/p/7976090.html