Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. package p106_Magic_Exchangeable_Words;
  2.  
  3.  
  4. import java.util.*;
  5.  
  6. public class Main {
  7.     public static void main(String[] args) {
  8.         String[] words = getWords();
  9.         boolean isExchangeable = isItExchangeable(words);
  10.         printResult(isExchangeable);
  11.     }
  12.  
  13.     private static void printResult(boolean isExchangeable) {
  14.         System.out.println(isExchangeable);
  15.     }
  16.  
  17.     private static boolean isItExchangeable(String[] words) {
  18.         Set<Character> set1 = getSet(words[0]);
  19.         Set<Character> set2 = getSet(words[1]);
  20.         if (set1.size() == set2.size()) {
  21.             return true;
  22.         }
  23.         return false;
  24.     }
  25.  
  26.     private static Set<Character> getSet(String word) {
  27.         Set<Character> set = new LinkedHashSet<>();
  28.         for (char c : word.toCharArray()) {
  29.             set.add(c);
  30.         }
  31.         return set;
  32.     }
  33.  
  34.     private static String[] getWords() {
  35.         Scanner scanner = new Scanner(System.in);
  36.         return scanner.nextLine().split("\\s+");
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement