fork download
  1.  
  2. import java.util.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. class Ideone {
  7. public static void main (String[] args) throws java.lang.Exception {
  8. Scanner scanner = new Scanner(System.in);
  9. String message, cipher;
  10. message = scanner.nextLine();
  11. cipher = scanner.nextLine();
  12. char[] decoded = new char [message.length()];
  13.  
  14. for (int i = 0; i < message.length(); i++) {
  15. if (message.charAt(i) == ' ') {
  16. decoded[i] = ' ';
  17. } else {
  18. decoded[i] = cipher.charAt(findIndex(message.charAt(i)));
  19. }
  20. }
  21. System.out.println(decoded);
  22. }
  23.  
  24. static int findIndex(char c) {
  25. String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  26. for (int i = 0; i < alphabet.length(); i++) {
  27. if (c == alphabet.charAt(i))
  28. return i;
  29. }
  30. return -1;
  31. }
  32. }
Success #stdin #stdout 0.14s 321344KB
stdin
LJBSLJL IJWWDEJ
KCFAGWRZMEXDNUYHVBOIJLSTPQ
stdout
DECODED MESSAGE