7-25 Read numbers (15 points)

7-25 Read numbers (15 points)
Input an integer and output the pinyin corresponding to each number. When the integer is negative, the fu word is output first. The pinyin corresponding to the ten numbers is as follows:

0: ling
1: yi
2: er
3: san
4: si
5: wu
6: liu
7: qi
8: ba
9: jiu
Input format:

Input gives an integer in one line, eg: 1234.

Tip: Integers include negative, zero, and positive numbers.

Output format:

Output the pinyin corresponding to the integer in one line. The pinyin of each number is separated by a space, and there is no final space at the end of the line. Such as yi er san si.

Input sample:

-600
output sample:

fu liu ling ling

import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int i=0;
        String str=String.valueOf(a);
        String [] array=new String[]{"ling","yi","er","san","si","wu","liu","qi","ba","jiu","fu"};
        for(;i<str.length()-1;i++){
            char c=str.charAt(i);
            if(c=='-'){
                System.out.print(array[10]+" ");
            }else if(c=='0'){
                System.out.print(array[0]+" ");
            }
            else if (c=='1'){
                System.out.print(array[1]+" ");
            }else if(c=='2'){
                System.out.print(array[2]+" ");
            }else if(c=='3'){
                System.out.print(array[3]+" ");
            }else if(c=='4'){
                System.out.print(array[4]+" ");
            }else if(c=='5'){
                System.out.print(array[5]+" ");
            }else if(c=='6'){
                System.out.print(array[6]+" ");
            }else if(c=='7'){
                System.out.print(array[7]+" ");
            }else if(c=='8'){
                System.out.print(array[8]+" ");
            }else if(c=='9'){
                System.out.print(array[9]+" ");
            }
        }
        if(i==str.length()-1){
            char c=str.charAt(i);
            if(c=='-'){
                System.out.print(array[10]);
            }else if(c=='0'){
                System.out.print(array[0]);
            }
            else if (c=='1'){
                System.out.print(array[1]);
            }else if(c=='2'){
                System.out.print(array[2]);
            }else if(c=='3'){
                System.out.print(array[3]);
            }else if(c=='4'){
                System.out.print(array[4]);
            }else if(c=='5'){
                System.out.print(array[5]);
            }else if(c=='6'){
                System.out.print(array[6]);
            }else if(c=='7'){
                System.out.print(array[7]);
            }else if(c=='8'){
                System.out.print(array[8]);
            }else if(c=='9'){
                System.out.print(array[9]);
            }
        }

    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324504691&siteId=291194637