Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5. import java.util.Scanner;
  6.  
  7. public class Main
  8. {
  9. public static void main(String[] args) throws IOException {
  10. // // расскомментить перед первым запуском, потом удалить
  11. PrintWriter fileOut = new PrintWriter("dict.txt");
  12. fileOut.println("Hello = Привет");
  13. fileOut.println("world = мир");
  14. fileOut.close();
  15. fileOut = new PrintWriter("text.txt");
  16. fileOut.println("Hello world");
  17. fileOut.close();
  18.  
  19. Map<String,String> dict = new HashMap<>();
  20. Scanner in = new Scanner(new File("dict.txt"));
  21. while(in.hasNext())
  22. {
  23. String []ss = in.nextLine().split(" = ");
  24. dict.put(ss[0],ss[1]);
  25.  
  26. }
  27. in = new Scanner(new File("text.txt"));
  28. while (in.hasNext())
  29. {
  30. String []ss = in.nextLine().split(" ");
  31. for (int i = 0; i<ss.length; i++)
  32. {
  33. System.out.print(dict.get(ss[i])+" ");
  34. }
  35. System.out.println();
  36.  
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement