要不要这么麻烦?
直接定义个数组,查表法,就行了
- import java.util.Scanner;
- public class Test {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- char[] ch = {'零','一','二','三','四','五','六','七','八','九'};
- String value = s.next();
- char[] c = value.toCharArray();
- for(int x = 0;x<c.length;x++){
- String str = c[x]+"";
- int num = new Integer(str);
- System.out.print(ch[num]);
- }
- s.close();
- }
- }
复制代码 |