Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.experis.cisco.test.ExperisCisco;
- public class ExperisTest
- {
- public static void main( String[] args )
- {
- String testStr = "race car";
- ExperisTest test = new ExperisTest();
- boolean isPalindrome = test.isPalindrome(testStr);
- System.out.println(isPalindrome);
- }
- /**
- * Identify if given string is a palindrome or not
- */
- public boolean isPalindrome( String text ){
- char[] arr = text.replaceAll("\\s+","").toCharArray();
- int i = 0 ;
- int k = arr.length -1;
- while ( i != k ){
- if ( arr[i] != arr[k] ){
- return false;
- }
- i++;
- k--;
- }
- return true;
- }
- }
Add Comment
Please, Sign In to add comment