This Java program checks whether an input string is a palindrome or not. A palindrome string is a string that remains the same when its characters are reversed.
Overall, this program correctly checks whether an input string is a palindrome or not. However, it could be improved by handling the case where the input string contains spaces or other special characters. In its current form, the program does not remove any spaces or special characters from the input string before checking for palindrome-ness.
import java.util.Scanner; class Palindrome_String { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter The String :"); String str = input.nextLine(); String rev = ""; int len = str.length(); for (int i = (len - 1); i >=0; --i) { rev = rev + str.charAt(i); } if (str.toLowerCase().equals(rev.toLowerCase())) { System.out.println(str + " is a Palindrome String."); } else { System.out.println(str + " is not a Palindrome String."); } } }
Enter The String :madam madam is a Palindrome String
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions