Check Palindrome String
This program checks if a string is palindrome.
Problem Statement
Write a Java program to check if a string is palindrome.
Source Code
| 1 | public class PalindromeCheck { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Palindrome Check"); |
| 4 | String str="madam"; |
| 5 | String rev=new StringBuilder(str).reverse().toString(); |
| 6 | if(str.equals(rev)) System.out.println("String is palindrome"); |
| 7 | else System.out.println("String is not palindrome"); |
| 8 | } |
| 9 | } |
Program Output
Eduinq Palindrome Check String is palindrome
Explanation
A StringBuilder is used to reverse the string, and the reversed version is compared with the original using equals(), demonstrating a straightforward palindrome check.