Guest User

Untitled

a guest
Jun 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1.  
  2. import java.util.*;
  3. /**
  4. * Write a description of class Anagram here.
  5. *
  6. * @author (your name)
  7. * @version (a version number or a date)
  8. */
  9. public class Anagram
  10. {
  11. public String check(String word1, String word2)
  12. {
  13. int count = 0;
  14. char array_word1[];
  15. array_word1 = new char[99];
  16. char array_word2[];
  17. array_word2 = new char[99];
  18. for (int i = 0; i < word1.length(); i++) // WORD 1 IS NOT ZERO INDEXED
  19. {
  20. array_word1[i] = word1.charAt(i); // Array is zero indexed
  21. }
  22. for (int i = 0; i < word2.length(); i++) // WORD 2 IS NOT ZERO INDEXED
  23. {
  24. array_word2[i] = word2.charAt(i); // Array is zero indexed
  25. }
  26.  
  27. java.util.Arrays.sort(array_word1);
  28. java.util.Arrays.sort(array_word2);
  29.  
  30. String temp1 = new String(array_word1);
  31. String temp2 = new String(array_word2);
  32.  
  33. if(temp1.equals(temp2))
  34. return "true";
  35. else
  36. return "false";
  37. }
  38. }
Add Comment
Please, Sign In to add comment