java program to check palindrome string using Queue

Published: 23 May 2021
on channel: Aman Tripathi
195
6

INSTAGRAM :   / javac_programming  
CODE :
import java.util.Queue;
import java.util.Scanner;
import java.util.LinkedList;
class PalindromeTest {

public static void main(String[] args) {

System.out.print("Enter any string:");
Scanner in=new Scanner(System.in);
String inputString = in.nextLine();
Queue queue = new LinkedList();

for (int i = inputString.length()-1; i _=0; i--) {
queue.add(inputString.charAt(i));
}

String reverseString = "";

while (!queue.isEmpty()) {
reverseString = reverseString+queue.remove();
}
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:xyzzyx
xyzzyx
The input String is a palindrome.
Output 2:

Enter any string:xyz
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 Queue with a duration of hours minute second in good quality, which was uploaded by the user Aman Tripathi 23 May 2021, share the link with friends and acquaintances, this video has already been watched 195 times on youtube and it was liked by 6 viewers. Enjoy your viewing!