7-23 币值转换

7-23 币值转换_第1张图片

import java.util.Scanner;


public class Main{
    public static void main(String[] args) {

     Scanner input=new Scanner(System.in);
        int num=input.nextInt();
        input.close();
        String numstr=num+"";
        String[] letters={"a","b","c","d","e","f","g","h","i","j"};
        String[] unit={"","S","B","Q","W","S","B","Q","Y","S"};

        String[] numstr_arr=numstr.split("");

        int[] numarr= new int[numstr_arr.length];
        //调过来存储
        int j=0;
        for(int i=numstr_arr.length-1;i>=0;i--){
            numarr[j]=Integer.parseInt(numstr_arr[i]);
            j=j+1;
        }

         if (numarr.length==1&&numarr[0]==0) {
            System.out.println("a");
        }
        else{
            for (int h=numarr.length-1;h>=0;h--) {
                if(numarr[h]!=0){
                    System.out.print(letters[numarr[h]]);
                    System.out.print(unit[h]);
                }
                //十 十万
                if(numarr[h]==0&&(h==1||h==5)&&numarr[h-1]!=0){
                    System.out.print(letters[0]);
                }
                //百 百万
                if(numarr[h]==0&&(h==2||h==6)&&numarr[h-2]!=0){
                    System.out.print(letters[0]);
                }
                //万 亿
                if(numarr[h]==0&&(h==4)){
                    System.out.print(unit[h]);
                }
            }
        }
        //System.out.println(re);
    }
}

你可能感兴趣的:(PAT,java,开发语言)