读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:
每个测试输入包含 1 个测试用例,即给出自然数 n 的值。这里保证 n 小于 10100。
输出格式:
在一行内输出 n 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音数字后没有空格。
输入样例:
1234567890987654321123456789
输出样例:
yi san wu
实现代码:
import java.util.Locale;标签:arr,JAVA,String,int,2522%,System,写出,1002,Scanner From: https://blog.51cto.com/u_15754851/5764385
import java.util.Scanner;
/**
* @author yx
* @date 2022-07-12 0:14
*/
/*
int 取值范围:2^31-1;最小数值为:-2^31
long 取值范围:-2^64“ 到”2^64 -1【考察点不是大数】
*/
//【考察的是字符串数组的创建】
// https://blog.csdn.net/weixin_53555211/article/details/124640337?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165755691016780366526094%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=165755691016780366526094&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~baidu_landing_v2~default-2-124640337-null-null.142^v32^pc_rank_34,185^v2^control&utm_term=java%E5%AE%9A%E4%B9%89%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%95%B0%E7%BB%84&spm=1018.2226.3001.4187
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s=scanner.next();
char[] arr_s=s.toCharArray();
int n=s.length();
int sum=0;
String[] arr=new String[]{"ling","yi","er","san","si","wu","liu","qi","ba","jiu","shi"};
for (int i = 0; i < n; i++) {
sum+=arr_s[i]-'0';
}
String num=new String(Integer.toString(sum));
char[] arr_n=num.toCharArray();
for (int i = 0; i < num.length(); i++) {
if(i!=0) System.out.print(" ");
System.out.print(arr[arr_n[i]-'0']);
}
}
}