Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Stack;
- public class Stack1 {
- public static void main(String[] args) {
- String test = "tacocat";
- if(isPalidrome(test)){
- System.out.println("yes");
- }else{
- System.out.println("no");
- }
- }
- public static boolean isPalidrome(String test) {
- int length = test.length();
- int x=0;
- Stack <Character> stack = new Stack<Character>();
- for(int i = 0; i < length/2; i++) {
- stack.push(test.charAt(i));
- if(length % 2 != 0 && i==length/2 + 1) {
- break;
- }
- if(stack.empty()){
- return false
- }
- while(i < length) {
- char test = stack.pop();
- if(fromStack != test.charAt(i)) {
- return false;
- }
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement