导航

L1-007 念数字 (10 分)java

Posted on 2018-11-16 21:22  风紧扯不扯呼  阅读(278)  评论(0)    收藏  举报

L1-007 念数字 (10 分)


import java.util.Scanner;
/**
		 * 
		 * @author 曹家伟
		 *
		 */
public class Main {

	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		if(n>0) {
			String str1=Integer.toString(n);
//		System.out.println(str1);
			int p=str1.length();
			int l=-1;
			char ch[]=new char[p];
//			System.out.println(p);
			ch=str1.toCharArray();
//			System.out.println(ch[1]);
			char a[]= {'0','1','2','3','4','5','6','7','8','9'};
			String str[]= {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
			for(int i=0;i<p;i++) {
				for(int j=0;j<10;j++) {
					if(ch[i]==a[j]) {
						l++;
						if(l<p-1) {
							System.out.print(str[j]+" ");
						}else {
							System.out.print(str[j]);

						}
					}
				}
			}
		}else if(n<0) {
			System.out.print("fu"+" ");
			int n1=Math.abs(n);
			String str1=Integer.toString(n1);
//			System.out.println(str1);
				int p=str1.length();
				int l=-1;
				char ch[]=new char[p];
				ch=str1.toCharArray();
				char a[]= {'0','1','2','3','4','5','6','7','8','9'};
				String str[]= {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
				for(int i=0;i<p;i++) {
					for(int j=0;j<10;j++) {
						if(ch[i]==a[j]) {
							l++;
							if(l<p-1) {
								System.out.print(str[j]+" ");
							}else {
								System.out.print(str[j]);

							}
						}
					}
				}
		}
		else {
			System.out.print("ling");
		}
	}

}