-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP6_5.java
More file actions
41 lines (36 loc) · 821 Bytes
/
P6_5.java
File metadata and controls
41 lines (36 loc) · 821 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
30
31
32
33
34
35
36
37
38
39
40
41
public class P6_5 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(isPalindromicString("A man, a plan, a canal, Panama"));
System.out.println(isPalindromicString("Ap,x,pA"));
System.out.println(isPalindromicString("Ap,x,pA"));
System.out.println(isPalindromicString(" "));
}
public static boolean isPalindromicString(String s)
{
if (s.equals("") || s.trim().length() == 0) return true;
int start = 0;
int end = s.length() -1;
s = s.toLowerCase();
while(start < end)
{
if(!Character.isLetter(s.charAt(start)))
{
start++;
continue;
}
if(!Character.isLetter(s.charAt(end)))
{
end--;
continue;
}
if(s.charAt(start) != s.charAt(end))
{
return false;
}
start++;
end--;
}
return true;
}
}