天天看點

1002 寫出這個數(JAVA)

輸入格式:

輸出格式:

輸入樣例:

1234567890987654321123456789      

輸出樣例:

yi san wu      

實作代碼:

import java.util.Locale;
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']);
        }
    }
}