conditions are met
but still error
package zh.codegym.task.task19.task1924;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/*
替换数字
*/
public class Solution {
public static Map<Integer, String> map = new HashMap<Integer, String>();
static {
map.put(0, "零");
map.put(1, "一");
map.put(2, "二");
map.put(3, "三");
map.put(4, "四");
map.put(5, "五");
map.put(6, "六");
map.put(7, "七");
map.put(8, "八");
map.put(9, "九");
map.put(10, "十");
map.put(11, "十一");
map.put(12, "十二");
}
public static void main(String[] args) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
FileReader fileReader = new FileReader(reader.readLine());
){
String temp = "";
String text = "";
String previous = "";
while (fileReader.ready()){
char c = (char) fileReader.read();
// Numbers after English are not replaced
if(previous.matches("^[a-zA-Z]+$") && String.valueOf(c).matches("^[0-9]*$")) {
text = text.concat(String.valueOf(c));
while (fileReader.ready()){
char c1 = (char) fileReader.read();
if (String.valueOf(c1).matches("^[0-9]*$")) {
text = text.concat(String.valueOf((char) c1));
}else {
text = text.concat(String.valueOf((char) c1));
break;
}
}
continue;
}
// put the number in temp
if (String.valueOf(c).matches("^[0-9]*$")) {
temp = temp.concat(String.valueOf(c));
if (fileReader.ready()) continue;
}
// Check that the temp numbers match
if (!temp.equals("") && map.containsKey(Integer.parseInt(temp))){
text = text.concat(map.get(Integer.parseInt(temp)));
if (fileReader.ready()) {text = text.concat(String.valueOf(c));
}else text = text.concat(String.valueOf(c));
temp = "";
continue;
}else {
text = text.concat(temp);
temp = "";
}
text = text.concat(String.valueOf(c));
previous = String.valueOf(c);
}
System.out.println(text);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}