java program to check palindrome string using Stack | palindrome String using java

Published: 22 May 2021
on channel: Aman Tripathi
481
15

Instagram |   / javac_programming  
import java.util.Stack;
import java.util.Scanner;
class PalindromeTest {

public static void main(String[] args) {

System.out.print("Enter any string:");
Scanner in=new Scanner(System.in);
String inputString = in.nextLine();
Stack stack = new Stack();

for (int i = 0; i _ inputString.length(); i++) {
stack.push(inputString.charAt(i));
}

String reverseString = "";

while (!stack.isEmpty()) {
reverseString = reverseString+stack.pop();
}

if (inputString.equals(reverseString))
System.out.println("The input String is a palindrome.");
else
System.out.println("The input String is not a palindrome.");

}
}
Output 1:

Enter any string:abccba
The input String is a palindrome.
Output 2:
Enter any string:abcdef
The input String is not a palindrome.


On this page of the site you can watch the video online java program to check palindrome string using Stack | palindrome String using java with a duration of hours minute second in good quality, which was uploaded by the user Aman Tripathi 22 May 2021, share the link with friends and acquaintances, this video has already been watched 481 times on youtube and it was liked by 15 viewers. Enjoy your viewing!