I would guess they have some other weird condition to appease like the ending "." that needs to be accounted for but not in the example file data.
Anyone know what it is so I can add it?
package com.codegym.task.task19.task1924;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
/*
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) {
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String fileName = br.readLine();
FileReader fr = new FileReader(fileName);
BufferedReader br2 = new BufferedReader(fr);
while (br2.ready())
{
String line = br2.readLine();
String tmpLine = line;
if (line.endsWith("."))
{
tmpLine = line.substring(0, line.length()-1);
}
for (String word : tmpLine.split(" "))
{
if (word.chars().allMatch( Character::isDigit ))
{
if (map.keySet().contains(Integer.parseInt(word)))
{
line = line.replaceFirst(word, map.get(Integer.parseInt(word)));
}
}
}
System.out.println(line);
}
br.close();
fr.close();
br2.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}