Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Puppy {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String word1 = scanner.nextLine();
  10. String word2 = scanner.nextLine();
  11.  
  12. String newWord = "";
  13.  
  14. int length = Math.min(word1.length(), word2.length());
  15. int differenceBetweenSizes = Math.abs(word1.length() - word2.length());
  16.  
  17. for (int i = 0; i < length; i++) {
  18.  
  19. int x = word1.charAt(i) - 'a';
  20. int y = word2.charAt(i) - 'a';
  21.  
  22. if (x == -65 || y == -65) {
  23. newWord += " ";
  24. continue;
  25. }
  26.  
  27. int result = Math.abs(x - y) + 'a';
  28.  
  29. char join = (char) result;
  30.  
  31. newWord += join;
  32. }
  33.  
  34. for (int i = differenceBetweenSizes; i > 0; i--) {
  35.  
  36. if (word1.length() < word2.length()) {
  37.  
  38. newWord += word2.charAt(word2.length() - i);
  39. }
  40. }
  41.  
  42. System.out.println(newWord);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement