Guest User

Untitled

a guest
Jan 17th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. package com.experis.cisco.test.ExperisCisco;
  2.  
  3. public class ExperisTest
  4. {
  5. public static void main( String[] args )
  6. {
  7.  
  8. String testStr = "race car";
  9. ExperisTest test = new ExperisTest();
  10. boolean isPalindrome = test.isPalindrome(testStr);
  11. System.out.println(isPalindrome);
  12.  
  13. }
  14.  
  15. /**
  16. * Identify if given string is a palindrome or not
  17. */
  18.  
  19. public boolean isPalindrome( String text ){
  20.  
  21.  
  22. char[] arr = text.replaceAll("\\s+","").toCharArray();
  23. int i = 0 ;
  24. int k = arr.length -1;
  25.  
  26. while ( i != k ){
  27.  
  28. if ( arr[i] != arr[k] ){
  29. return false;
  30. }
  31.  
  32. i++;
  33. k--;
  34.  
  35. }
  36.  
  37. return true;
  38.  
  39. }
  40.  
  41.  
  42.  
  43. }
Add Comment
Please, Sign In to add comment