-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindromeString.java
More file actions
36 lines (34 loc) · 951 Bytes
/
PalindromeString.java
File metadata and controls
36 lines (34 loc) · 951 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
package Codes;
import java.util.Scanner;
public class PalindromeString {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for (int i=0;i<t;i++) {
String input = sc.next();
System.out.println(palindrome(input));
}
}
static boolean palindrome(String input){
int left=0;
int right=input.length()-1;
input=input.toUpperCase();
while (left<=right){
char cleft=input.charAt(left);
char cright=input.charAt(right);
if (!(cleft >= 'a' && cleft <= 'z')){
left++;
}
else if (!(cright >= 'a' && cright <= 'z')){
right--;
}
else if (cleft==cright){
left++;
right--;
}
else
return false;
}
return true;
}
}