-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring1.java
More file actions
36 lines (34 loc) · 839 Bytes
/
string1.java
File metadata and controls
36 lines (34 loc) · 839 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
class string1
{
public static void main(String[] args) {
String s="OP";
//isPalindrome(s);
if(isPalindrome(s))
{
System.out.println("Palindrome");
}
else{
System.out.println("Not a palindrome");
}
}
public static boolean isPalindrome(String s) {
String lo=s.toLowerCase();
String rev="";
for(int i=0;i<lo.length();i++)
{
char letter=lo.charAt(i);
if(letter>='a' && letter<='z')
{
rev=rev+letter;
}
}
String fin="";
for(int j=rev.length()-1;j>=0;j--)
{
fin=fin+rev.charAt(j);
}
System.out.println("fin="+fin);
return rev.equals(fin);
//System.out.println("st="+rev);
}
}