当前位置:网站首页>1002 Write the number (20 points)

1002 Write the number (20 points)

2022-08-11 07:47:00 dumb bit

题目要求:
在这里插入图片描述
代码:

import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
    
        Scanner scan = new Scanner(System.in);
        //input receive
        String str = scan.nextLine();

        //Define the correspondence between numbers and pinyin in advance
        String result[] = {
    "ling","yi","er","san","si","wu","liu","qi","ba","jiu"};

        //和
        int sum = 0;

        //Please enter the sum of each bit
        String[] strs = str.split("");

        for (int i = 0; i < str.length(); i++) {
    
            sum += Integer.valueOf(strs[i]);
        }

        //对应输出
        for (int i = 0; i < (sum + "").length(); i++) {
    
            int index = Integer.valueOf((sum + "").split("")[i]);

            if (i == (sum + "").length() - 1){
    
                System.out.print(result[index]);
            } else{
    
                System.out.print(result[index] + " ");
            }

        }
    }
}

结果:
在这里插入图片描述

原网站

版权声明
本文为[dumb bit]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110645413249.html