-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubStringPallindrome.java
More file actions
54 lines (40 loc) · 876 Bytes
/
SubStringPallindrome.java
File metadata and controls
54 lines (40 loc) · 876 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
42
43
44
45
46
47
48
49
50
51
52
53
54
package poorvatutorial1;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
public class SubStringPallindrome {
public static boolean CheckPallindrome(String str)
{
int start = 0;
int end =str.length()- 1;
while(start < end)
{
if(str.charAt(start) != str.charAt(end))
{
return false;
}
start++;
end--;
}
return true;
}
public static void main(String[] args) {
String s = "pooorva";
int count = 0;
HashSet<String> h = new HashSet<String>();
for(int i = 0; i < s.length(); i++)
{
for(int j = i+1; j < s.length(); j++)
{
//System.out.println(s.substring(i, j+1));
if(CheckPallindrome(s.substring(i, j+1)))
{
System.out.println((s.substring(i, j+1)));
//h.add(s.substring(i,j+1));
count++;
}
}
}
System.out.println(count);
}
}