Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package p106_Magic_Exchangeable_Words;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- String[] words = getWords();
- boolean isExchangeable = isItExchangeable(words);
- printResult(isExchangeable);
- }
- private static void printResult(boolean isExchangeable) {
- System.out.println(isExchangeable);
- }
- private static boolean isItExchangeable(String[] words) {
- Set<Character> set1 = getSet(words[0]);
- Set<Character> set2 = getSet(words[1]);
- if (set1.size() == set2.size()) {
- return true;
- }
- return false;
- }
- private static Set<Character> getSet(String word) {
- Set<Character> set = new LinkedHashSet<>();
- for (char c : word.toCharArray()) {
- set.add(c);
- }
- return set;
- }
- private static String[] getWords() {
- Scanner scanner = new Scanner(System.in);
- return scanner.nextLine().split("\\s+");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement