Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Java program to check palindrome string using Queue

Java programs

In this Program, we are going to share a Java program to check palindrome string using Queue. If you are a Java beginner and want to start learning the Java programming, then keep your close attention in this tutorial as I am going to share how to write a Java program to check palindrome string using Queue.

  • Collection of 100+ Java problems with solutions.

Java program to check palindrome string using Queue with the output

Copy the below Java program and execute it with the help of Javac compiler. At the end of this program, We have shared the output of this program.

import java.util.Queue;
import java.util.Scanner;
import java.util.LinkedList;

class PalindromeExample {

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

    }
}

Program Output

Enter any string:xyzzyx
xyzzyx
The input String is a palindrome.

The post Java program to check palindrome string using Queue appeared first on FreeWebMentor.



This post first appeared on Programming Blog Focused On Web Technologies, please read the originial post: here

Share the post

Java program to check palindrome string using Queue

×

Subscribe to Programming Blog Focused On Web Technologies

Get updates delivered right to your inbox!

Thank you for your subscription

×