Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- import java.util.ArrayList;
- class Anagram {
- public static void getAnagram(String word1, String word2) {
- ArrayList<Character> wordlist1 = new ArrayList<Character>();
- ArrayList<Character> wordlist2 = new ArrayList<Character>();
- for(int i = 0;i < word1.length();++i) {
- for(int j = 0;j < word2.length();++j) {
- if(word1.charAt(i) == word2.charAt(j)) {
- wordlist2.add(word2.charAt(j));
- }
- }
- }
- for(int i = 0;i < word2.length();++i) {
- for(int j = 0;j < word1.length();++j) {
- if(word2.charAt(i) == word1.charAt(j)) {
- wordlist1.add(word1.charAt(j));
- }
- }
- }
- System.out.println((word1.length() + word2.length()) - (wordlist1.size() + wordlist2.size()));
- //return (word1.length() + word2.length()) - (wordlist1.size() + wordlist2.size());
- }
- }
- public class HackerRankAnagram {
- public static void main(String[] args) {
- //Anagram.getAnagram("fcrxzwscanmligyxyvym".toLowerCase().toCharArray(), "jxwtrhvujlmrpdoqbisbwhmgpmeoke".toLowerCase().toCharArray());
- for(int i = 0; i < 10;++i) {
- for(int j = 0; j < 10;++j) {
- System.out.println("loop2");
- break;
- }
- System.out.println("loop1");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement