Last active
March 1, 2016 22:39
-
-
Save Viacheslav77/ab35bcff717fc53debea to your computer and use it in GitHub Desktop.
Написать программу переводчик, которая будет переводить текст, написанный на одном языке, на другой язык согласно заранее составленному словарю
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package Dictionary; | |
| import java.util.HashMap; | |
| import java.util.Map; | |
| public class Dictionary { | |
| private Map <String,String> Dic; | |
| public Dictionary (){ | |
| Dic = new HashMap <String,String> (); | |
| } | |
| public void setWord (String w1, String w2){ | |
| Dic.put(w1, w2); | |
| } | |
| public String getW2 (String w1){ | |
| return Dic.get(w1); | |
| } | |
| public String getW1 (String w2){ | |
| return Dic.get(w2); | |
| } | |
| public void getTransfer(String text,Dictionary d ){ | |
| System.out.println ("Фраза для перевода - " + text + "\n переводим ..."); | |
| String [] tmp = text.split(" "); | |
| StringBuilder sb = new StringBuilder (); | |
| for(String s: tmp) | |
| sb.append(d.getW2(s)+" "); | |
| System.out.print("Перевод : " + sb); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package Dictionary; | |
| /*Написать программу переводчик, которая будет переводить текст, | |
| написанный на одном языке, на другой язык согласно заранее | |
| составленному словарю.*/ | |
| public class MyClass { | |
| public static void main(String[] args) { | |
| String [] s1 = {"Hello", "!", "world", "My", "name"}; | |
| String [] s2 = {"Привет","!", "мир", "моё", "имя"}; | |
| Dictionary d = new Dictionary(); | |
| for(int i=0; i < s1.length; i++) | |
| d.setWord(s1[i], s2[i]); | |
| String text = "Hello world !"; | |
| d.getTransfer(text, d); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment