emodev

Untitled

Dec 5th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. package z_finalDemoExam;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Deciphering {
  6.     public static void main(String[] args) {
  7.         Scanner console = new Scanner(System.in);
  8.         String line = console.nextLine();
  9.         String[] substringChars = console.nextLine().split("\\s+");
  10.         String toReplace = substringChars[0];
  11.         String replacement = substringChars[1];
  12.  
  13.         StringBuilder result = new StringBuilder();
  14.         for (int i = 0; i < line.length(); i++) {
  15.             char charInLine = line.charAt(i);
  16.             if (!isValid(charInLine)){
  17.                 System.out.println("This is not the book you are looking for.");
  18.                 return;
  19.             }
  20.            result.append((char) (charInLine - 3));
  21.         }
  22.  
  23.         for (int i = 0; i < result.length(); i++) {
  24.  
  25.         }
  26.  
  27.         String setaa = result.toString();
  28.         setaa = setaa.replaceAll(toReplace,replacement);
  29.  
  30.         System.out.println(setaa);
  31.  
  32.     }
  33.  
  34.  
  35.     private static boolean isValid(char letter){
  36.         boolean result = true;
  37.         if (letter < 'd'){
  38.             result = false;
  39.         }
  40.  
  41.         if (letter == '#' || letter == ',' || letter == '|'){
  42.             result = true;
  43.         }
  44.  
  45.         return result;
  46.     }
  47. }
Add Comment
Please, Sign In to add comment