Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DemoFinalExam;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Deciphering {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String line = reader.readLine();
- String newLine = "";
- if (isValid(line)) {
- for (int i = 0; i < line.length(); i++) {
- char symbol = (char) (line.charAt(i) - 3);
- newLine += symbol;
- }
- String substring = reader.readLine();
- String[] separateSubstrings = substring.split(" ");
- String firstSub = separateSubstrings[0];
- String secondSub = separateSubstrings[1];
- String str = newLine.replaceAll(firstSub, secondSub);
- System.out.println(str);
- } else {
- System.out.println("This is not the book you are looking for.");
- }
- }
- private static boolean isValid(String firstLine) {
- for (int i = 0; i < firstLine.length(); i++) {
- int symbol = (int) (firstLine.charAt(i));
- if (!(symbol == 35 || (symbol >= 100 && symbol <= 125))) {
- return false;
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement