-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidpalindrome.java
More file actions
29 lines (28 loc) · 831 Bytes
/
validpalindrome.java
File metadata and controls
29 lines (28 loc) · 831 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.*;
class validpalindrome{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter the string to check");
String str = sc.nextLine();
int i=0;
int j=str.length()-1;
while(i<j){
Character start=str.charAt(i);
Character end =str.charAt(j);
if(!Character.isLetterOrDigit(start)){
i++;
continue;
}
if(!Character.isLetterOrDigit(end)){
j--;
continue;
}
if(Character.toLowerCase(start) !=Character.toLowerCase(end)){
System.out.println("Not");
}
i++;
j--;
}
System.out.println("yes");
}
}