- import java.math.BigInteger;
- import java.util.Scanner;
- public class Demo6_array {
- public static void main(String[] args) {
- // 定义查表的数组
- char[] chs = {'0','1','2','3','4','5','6','7','8','9'};
-
- Scanner sc = new Scanner(System.in);
- while (true) { // 只要输入错误就继续
- String line = sc.nextLine();
- try {
- new BigInteger(line); // 放到BigInteger
- for (int i = 0; i < line.length(); i++) {
- char ch = line.charAt(i);
- System.out.print(chs[ch - '0']);
- }
- break; // 正常输出就break
- } catch (Exception e) {
- System.out.println("请输入纯数字字符:");
- }
- }
- }
- }
复制代码 |
|