0% found this document useful (0 votes)
218 views1 page

Palindrome Check Using Queue

This Java code takes a user-input string, reverses it using a queue, and compares the reversed string to the original to determine if it is a palindrome. It prompts the user to enter a string, uses a queue and loops to add the characters of the string in reverse order to the queue, builds a reversed string by removing from the queue, and prints whether the original and reversed strings are equal, identifying the input as a palindrome or not.

Uploaded by

Abhishek__kr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
218 views1 page

Palindrome Check Using Queue

This Java code takes a user-input string, reverses it using a queue, and compares the reversed string to the original to determine if it is a palindrome. It prompts the user to enter a string, uses a queue and loops to add the characters of the string in reverse order to the queue, builds a reversed string by removing from the queue, and prints whether the original and reversed strings are equal, identifying the input as a palindrome or not.

Uploaded by

Abhishek__kr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

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.");

}
}

You might also like