0% found this document useful (0 votes)
2 views2 pages

ISC Class12 Advanced Java EPractical File

The document outlines a program for checking if a string is a palindrome. It includes an algorithm that processes the input string by converting it to lowercase and removing spaces, then compares it with its reversed version. The provided Java source code implements this algorithm and demonstrates its functionality with an example output.

Uploaded by

harshitnegi866
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

ISC Class12 Advanced Java EPractical File

The document outlines a program for checking if a string is a palindrome. It includes an algorithm that processes the input string by converting it to lowercase and removing spaces, then compares it with its reversed version. The provided Java source code implements this algorithm and demonstrates its functionality with an example output.

Uploaded by

harshitnegi866
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Class 12 ISC Computer Science E-Practical File

Program 1: Palindrome Checker for Strings


Algorithm:

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:

original: Stores the original input string


processed: Lowercased, space-removed version of original
reversed: Stores the reversed version of the string

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.

You might also like