Program to check whether the given string is palindrome or not in Java

 



Code:

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        String or, re = "";
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the string: ");
        or = sc.nextLine();
        int length = or.length();

        for (int i = length - 1; i >= 0; i--) {
            re = re + or.charAt(i);
        }
        if (or.equals(re)) {
            System.out.println("Entered string is Palindrome");
        } else {
            System.out.println("Entered string is not Palindrome");
        }
    }
}

Output:

AJ Blogs

Hello everyone, My name Arth and I like to write about what I learn. Follow My Website - https://sites.google.com/view/aj-blogs/home

Post a Comment

Previous Post Next Post
Best Programming Books

Facebook

AJ Facebook
Checkout Our Facebook Page
AJ Blogs
Checkout Our Instagram Page