-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathPalindrome.java
More file actions
29 lines (24 loc) · 816 Bytes
/
Copy pathPalindrome.java
File metadata and controls
29 lines (24 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.Scanner;
import java.util.*;
import java.io.*;
class Main {
public static String Palindrome(String str) {
// code goes here
// Remove non-alphanumeric characters
String strProcessed = str.replaceAll("[^a-zA-Z0-9]", "");
// Check for inequality in pairs
int strProcessedLength = strProcessed.length();
for (int index = 0; index <= strProcessedLength / 2; index++) {
if (strProcessed.charAt(index) != strProcessed.charAt(strProcessedLength - 1 - index)) {
return "false";
}
}
// If no inequality, must be palindrome
return "true";
}
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
System.out.print(Palindrome(s.nextLine()));
}
}