Advertisement
The_Minecrafter3

Untitled

Dec 10th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3. import java.util.ArrayList;
  4.  
  5. class Anagram {
  6.     public static void getAnagram(String word1, String word2) {
  7.        
  8.         ArrayList<Character> wordlist1 = new ArrayList<Character>();
  9.         ArrayList<Character> wordlist2 = new ArrayList<Character>();
  10.         for(int i = 0;i < word1.length();++i) {
  11.             for(int j = 0;j < word2.length();++j) {
  12.                 if(word1.charAt(i) == word2.charAt(j)) {
  13.                     wordlist2.add(word2.charAt(j));
  14.                 }
  15.             }
  16.         }
  17.         for(int i = 0;i < word2.length();++i) {
  18.             for(int j = 0;j < word1.length();++j) {
  19.                 if(word2.charAt(i) == word1.charAt(j)) {
  20.                     wordlist1.add(word1.charAt(j));
  21.                 }
  22.             }
  23.         }
  24.         System.out.println((word1.length() + word2.length())  - (wordlist1.size() + wordlist2.size()));
  25.         //return (word1.length() + word2.length())  - (wordlist1.size() + wordlist2.size());
  26.     }
  27. }
  28.  
  29. public class HackerRankAnagram {
  30.     public static void main(String[] args) {
  31.         //Anagram.getAnagram("fcrxzwscanmligyxyvym".toLowerCase().toCharArray(), "jxwtrhvujlmrpdoqbisbwhmgpmeoke".toLowerCase().toCharArray());
  32.         for(int i = 0; i < 10;++i) {
  33.             for(int j = 0; j < 10;++j) {
  34.                 System.out.println("loop2");
  35.                 break;
  36.             }
  37.             System.out.println("loop1");
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement