Skip to content

Latest commit

 

History

History
45 lines (38 loc) · 1.24 KB

2023-12-14-check-for-palindrome-string.md

File metadata and controls

45 lines (38 loc) · 1.24 KB
layout title author categories toc description
post
Java Program To Check If the given String Is Palindrome or Not
gaurav
Java Programs
Core Java
false
In this tutorial, we will see a Java program to check if the given String is palindrome or not.

In this tutorial, we will see a Java program to check if the given String is palindrome or not.

Java Program To Check If the given String Is Palindrome or Not

/**
 * A Java program to check if the given string is palindrome or not.
 * @author coderolls.com
 */
public class PalindromeString {

    public static void main(String[] args) {
        String str1 = "racecar";
        checkIfPalindrome(str1);
    }

    private static void checkIfPalindrome(String str) {
        String reversedString = "";
        int len = str.length();
        for (int i = (len - 1); i >= 0; --i) {
            reversedString = reversedString + str.charAt(i);
        }
        if (str.equalsIgnoreCase(reversedString)) {
            System.out.println("The String '" + str + "' is a Palindrome String.");
        } else {
            System.out.println("The String '" + str + "' is not a Palindrome String.");
        }
    }
}

Output

The String 'racecar' is a Palindrome String.