ISC Class12 Advanced Java EPractical File
ISC Class12 Advanced Java EPractical File
1. Start
2. Read a string input from the user
3. Convert the string to lowercase and remove spaces
4. Reverse the string
5. Compare the reversed string with the original
6. If they are equal, it's a palindrome
7. Else, it's not a palindrome
8. End
Variable Description:
Source Code:
import java.util.Scanner;
class PalindromeChecker {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a string: ");
String original = sc.nextLine();
String processed = original.toLowerCase().replaceAll(" ", "");
String reversed = new StringBuilder(processed).reverse().toString();
if (processed.equals(reversed)) {
System.out.println("The string is a palindrome.");
} else {
System.out.println("The string is not a palindrome.");
}
}
}
Output:
Enter a string: Madam
The string is a palindrome.