Definition: A palindrome is a string that reads the same forward and backward.
For example, "abcba" is a palindrome, "abab" is not.
Please implement this method to
return true if the parameter is a palindrome and false otherwise.
*/
- public class Palindrome {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.println(isPalindrome("cbc"));
- }
- public static boolean isPalindrome(String s) {
- /*
- Definition: A palindrome is a string that reads the same forward and backward.
- For example, "abcba" is a palindrome, "abab" is not.
- Please implement this method to
- return true if the parameter is a palindrome and false otherwise.
- */
- String temp;
- int len = s.length();
- char []arr = new char[len];
- for(int i=len-1,j=0;i>=0;i--,j++)
- {
- arr[j]=s.charAt(i);
- }
- temp = new String(arr);
- System.out.println("temp "+temp+"\ns "+s);
- if(temp.equals(s))
- return true;
- return false;
- }
- }
Download Link: Click Here

0 comments:
Post a Comment