plaindromX

import java.util.*; public class Main { public static boolean main(String[] args) { // from Ratan Kadam String str = "cdccdXdccdc"; Stack myStack = new Stack(); char[] chararr = str.toCharArray(); boolean bool=true; if( (chararr.length %2) != 1 ) { System.out.print("From length the given string is not palindrom.."); return false; } for(int i=0;i<chararr.length;i++) { int flag; if( chararr[i] != 'X') flag=0; else {flag =1; i=i+1;} // pointing to next location i.e. after X} if(flag==0) { myStack.push(chararr[i]); } else { if (chararr[i] != (char) myStack.pop()) { System.out.print("Not a palindrom.."); bool=false; return false; } } } System.out.print("The given string is Palindrom"); return true; } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.