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
String reversed using StringBuilder. - Original compared with reversed. - Together demonstrates palindrome check. Conclusion: Shows how to check if string is palindrome.