Advertisement
Edzhevit

Deciphering

Dec 3rd, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package DemoFinalExam;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6.  
  7. public class Deciphering {
  8.     public static void main(String[] args) throws IOException {
  9.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  10.  
  11.         String line = reader.readLine();
  12.         String newLine = "";
  13.  
  14.         if (isValid(line)) {
  15.  
  16.             for (int i = 0; i < line.length(); i++) {
  17.                 char symbol = (char) (line.charAt(i) - 3);
  18.                 newLine += symbol;
  19.  
  20.             }
  21.  
  22.             String substring = reader.readLine();
  23.             String[] separateSubstrings = substring.split(" ");
  24.             String firstSub = separateSubstrings[0];
  25.             String secondSub = separateSubstrings[1];
  26.  
  27.             String str = newLine.replaceAll(firstSub, secondSub);
  28.  
  29.  
  30.             System.out.println(str);
  31.         } else {
  32.             System.out.println("This is not the book you are looking for.");
  33.         }
  34.     }
  35.  
  36.     private static boolean isValid(String firstLine) {
  37.         for (int i = 0; i < firstLine.length(); i++) {
  38.             int symbol = (int) (firstLine.charAt(i));
  39.             if (!(symbol == 35 || (symbol >= 100 && symbol <= 125))) {
  40.                 return false;
  41.             }
  42.         }
  43.         return true;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement