Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / Неправильно работает программа / 1 сообщений из 1, страница 1 из 1
26.12.2018, 14:26
    #39753439
nastyaa
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Неправильно работает программа
Я хочу перевести слово компьютер на латинский. Он должен выдать - kompıýter, а почему конвертирует вот так с мягким знаком - kompьıýter. В латинском нету мягкого знака. Как можно исправить ошибку
[JAVA]import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {
public static void main(String[] args) throws IOException {
final String DEFAULT_ENCODING = "utf-8";

if(args.length < 2 || args.length > 3) {
System.out.println("Неверное количество аргументов");
System.exit(1);
}

String inputFilePath = args[0];
String outputFilePath = args[1];
String fileEncoding = args.length == 2 ? DEFAULT_ENCODING : args[2];







BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream(inputFilePath), fileEncoding));
File file = new File(outputFilePath);
FileOutputStream fileOutputStream = new FileOutputStream(file, false);

Writer writer = new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8);

String line;
StringBuilder result = new StringBuilder();

Map<String, String> dictionary = new Dictionary().getDictionary();

while ((line = in.readLine()) != null) {
String outLine = convertString(line, dictionary) + System.getProperty("line.separator");
System.out.println(line);
System.out.println(outLine);
result.append(outLine) ;
}

writer.write(result.toString());

in.close();
writer.flush();
writer.close();

}


public static String convertString(String str, Map<String, String> dictionary) {
char[] chars = str.toCharArray();
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < chars.length; i++) {
if (dictionary.containsKey(Character.toString(chars[i]))) {
stringBuilder.append(dictionary.get(Character.toString(chars[i])));
continue;
}
stringBuilder.append(chars[i]);
}
return stringBuilder.toString();
}
}

class Dictionary {
private Map<String, String> dictionary;

public Dictionary() {
dictionary = new HashMap<>();
dictionary = new HashMap<>();
dictionary.put("а", "a");
dictionary.put("А", "A");
dictionary.put("ә", "á");
dictionary.put("Ә", "Á");
dictionary.put("б", "b");
dictionary.put("Б", "B");
dictionary.put("д", "d");
dictionary.put("Д", "D");
dictionary.put("е", "e");
dictionary.put("E", "E");
dictionary.put("ф", "f");
dictionary.put("Ф", "F");
dictionary.put("г", "g");
dictionary.put("Г", "G");
dictionary.put("ғ", "ǵ");
dictionary.put("Ғ", "Ǵ");
dictionary.put("х", "h");
dictionary.put("Х", "H");
dictionary.put("һ", "һ");
dictionary.put("Һ", "Һ");
dictionary.put("і", "і");
dictionary.put("І", "I");
dictionary.put("и", "ı");
dictionary.put("И", "I");
dictionary.put("й", "ı");
dictionary.put("Й", "I");
dictionary.put("ж", "j");
dictionary.put("Ж", "J");
dictionary.put("к", "k");
dictionary.put("К", "К");
dictionary.put("л", "l");
dictionary.put("Л", "L");
dictionary.put("м", "m");
dictionary.put("М", "M");


}

public Map<String, String> getDictionary() {
return dictionary;

}
}
[/JAVA]
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / Неправильно работает программа / 1 сообщений из 1, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]