- import java.util.*;
- /**
- * 2、 从键盘接受一个数字,列出该数字的中文表示格式,例如:键盘输入123,打印出一二三;键盘输入3103,打印出三一零三。
- */
- public class Answer {
- public static void main(String[] args)
- {
-
- System.out.println("请输入数字:");
- String[] s={"零","一","二","三","四","五","六","七","八","九"};
- while(true)
- {
- Scanner s1=new Scanner(System.in);
- String str=s1.nextLine();
- for (int i = 0; i < str.length(); i++)
- {
- int k= Integer.parseInt(String.valueOf(str.charAt(i)));
- if(k>=0&&k<10)
- {
- System.out.print(s[k]);
- }
- else
- {
- System.out.print("请重新输入数字"+"\n");
- break;
- }
- }
-
- System.out.println("\n");
- }
-
- }
- }
复制代码 |