Skip to content

Commit 93f9c8c

Browse files
authored
Merge pull request #70 from mdsarfarazalam840/patch-1
Create Palindrom_checkerwithJava.java
2 parents 156da09 + 500ca05 commit 93f9c8c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Palindrom_checkerwithJava.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.Scanner;
2+
3+
public class PalindromeChecker {
4+
5+
public static boolean isPalindrome(String str) {
6+
str = str.replaceAll("[^a-zA-Z0-9]", "").toLowerCase(); // Remove non-alphanumeric characters and convert to lowercase
7+
int left = 0;
8+
int right = str.length() - 1;
9+
10+
while (left < right) {
11+
if (str.charAt(left) != str.charAt(right)) {
12+
return false; // Characters at the left and right positions don't match
13+
}
14+
left++;
15+
right--;
16+
}
17+
18+
return true; // All characters matched, it's a palindrome
19+
}
20+
21+
public static void main(String[] args) {
22+
Scanner scanner = new Scanner(System.in);
23+
24+
System.out.print("Enter a string: ");
25+
String input = scanner.nextLine();
26+
27+
if (isPalindrome(input)) {
28+
System.out.println("The input is a palindrome.");
29+
} else {
30+
System.out.println("The input is not a palindrome.");
31+
}
32+
33+
scanner.close();
34+
}
35+
}

0 commit comments

Comments
 (0)