public static void main(String[] args) {
//创建集合对象
Map<String, String> m = new HashMap<>();
//将元素添加到集合
m.put("0","零");
m.put("1","一");
m.put("2","二");
m.put("3","三");
m.put("4","四");
m.put("5","五");
m.put("6","六");
m.put("7","七");
m.put("8","八");
m.put("9","九");
//键盘输入数字
Scanner c = new Scanner(System.in);
//把输入的数字转换成字符串
String nextLine = c.nextLine();
//把字符串转换成字符数组
char[] charArray = nextLine.toCharArray();
//遍历字符数组
for (char d : charArray){
//打印出对应的数字
System.out.print(m.get(String.valueOf(d)));
}
}
} |
|