Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /**
- * Write a description of class Anagram here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class Anagram
- {
- public String check(String word1, String word2)
- {
- int count = 0;
- char array_word1[];
- array_word1 = new char[99];
- char array_word2[];
- array_word2 = new char[99];
- for (int i = 0; i < word1.length(); i++) // WORD 1 IS NOT ZERO INDEXED
- {
- array_word1[i] = word1.charAt(i); // Array is zero indexed
- }
- for (int i = 0; i < word2.length(); i++) // WORD 2 IS NOT ZERO INDEXED
- {
- array_word2[i] = word2.charAt(i); // Array is zero indexed
- }
- java.util.Arrays.sort(array_word1);
- java.util.Arrays.sort(array_word2);
- String temp1 = new String(array_word1);
- String temp2 = new String(array_word2);
- if(temp1.equals(temp2))
- return "true";
- else
- return "false";
- }
- }
Add Comment
Please, Sign In to add comment