Please help, whats wrong with this. Maybe there are some unknown (unpublished) requirements in the description to task.
package com.codegym.task.task19.task1924;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/*
Replacing numbers
*/
public class Solution {
public static Map<Integer, String> map = new HashMap<Integer, String>();
static{
map.put(0, "zero");
map.put(1, "one");
map.put(2, "two");
map.put(3, "three");
map.put(4, "four");
map.put(5, "five");
map.put(6, "six");
map.put(7, "seven");
map.put(8, "eight");
map.put(9, "nine");
map.put(10, "ten");
map.put(11, "eleven");
map.put(12, "twelve");
}
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
reader.close();
Scanner scanner = new Scanner(new FileReader(fileName));
while(scanner.hasNext()){
String str = scanner.next();
String str1 = str; //знаки препинания
String str2 = str;
char[] chr = str.toCharArray();
if(!Character.isDigit(chr[(chr.length-1)])){
try{
str1 = str.substring(str.length()-1);
str2 = str.substring(0, str.length()-1);
str = map.getOrDefault(Integer.parseInt(str2), str2) + str1;
}
catch(Exception e){
;
}
}else{
str = map.getOrDefault(Integer.parseInt(str), str);
}
System.out.print(str + " ");
}
scanner.close();
}
}