Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. private static Scanner input = new Scanner(System.in);
  2. private static HashMap<Character, Character> replace = new HashMap<>();
  3.  
  4. private static void replace() {
  5. try {
  6. Character a = null;
  7. Character b = null;
  8. System.out.println("Choose a letter to replace.");
  9. a = input.nextLine().charAt(0);
  10. System.out.println("Choose a replacement.");
  11. b = input.nextLine().charAt(0);
  12.  
  13. replace.put(Character.toUpperCase(a), Character.toUpperCase(b));
  14.  
  15. Test.convert();
  16. Test.replace();
  17. } catch (Exception e) {
  18. System.out.println("Error with input.");
  19. Test.replace();
  20. }
  21. }
  22.  
  23. private static void convert() {
  24. String input = "N INLZKI RNI FPGMZMT ZLF OKKCF, NIS TMTI LVT NHJZLZKPF. JPL ZL RNIIKL FPGMZMT LGTNFKI OGKH QZLVZI. NI TITHX NL LVT WNLTF ZF CTFF OKGHZSNJCT, OKG VT ZF BIKQI NIS RNGGZTFVZF JNIITG KDTICX. JPL LVT LGNZLKG HKMTF NHKIWFL LVKFT QZLVZI LVT WNLT OGTTCX, VZF QVZFDTGF GPFLCZIW LVGKPWV NCC LVT NCCTXF, VTNGS ZI LVT MTGX VNCCF KO WKMTGIHTIL ZLFTCO. OKG LVT LGNZLKG NDDTNGF IKL N LGNZLKG; VT FDTNBF ZI NRRTILF ONHZCZNG LK VZF MZRLZHF, NIS VT QTNGF LVTZG ONRT NIS LVTZG NGWPHTILF, VT NDDTNCF LK LVT JNFTITFF LVNL CZTF STTD ZI LVTVTNGLF KO NCC HTI. VT GKLF LVT FKPC KO N INLZKI, VT QKGBF FTRGTLCX NIS PIBIKQI ZI LVT IZWVL LK PISTGHZIT LVT DZCCNGF KO LVT RZLX, VT ZIOTRLF LVT JKSX DKCZLZR FK LVNL ZL RNI IK CKIWTG GTFZFL. N HPGSTGTG ZF CTFF LK OTNG. \r\n" +
  25. "\r\n" +
  26. "-HNGRPF LPCCZPF RZRTGK \r\n" +
  27. "";
  28. String output = "";
  29. char[] unconverted = new char[input.length()];
  30. char[] converted = new char[input.length()];
  31.  
  32. for (int i = 0; i < input.length(); i++) {
  33. unconverted[i] = input.charAt(i);
  34. }
  35.  
  36. for (int i = 0; i < input.length(); i++) {
  37. Character r = replace.get(input.charAt(i));
  38. converted[i] = (r != null) ? r : input.charAt(i);
  39. }
  40.  
  41. for (char c : converted) {
  42. output += c;
  43. }
  44.  
  45. System.out.println(output);
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement