-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckPalindrome
More file actions
57 lines (41 loc) · 926 Bytes
/
CheckPalindrome
File metadata and controls
57 lines (41 loc) · 926 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
55
56
57
//check a String is palindrome or not using recursion
import java.io.*;
public class CheckPal {
//static int count = 1;
static boolean b1 = true;
public static boolean check(char ar[], int n, int t )
{
if(n==t)
{
return b1;
}
if(ar[n]!=ar[t-1])
{
b1 = false;
}
if(n<t)
{
return check(ar, n+1, t-1);
}
return b1;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader inp=new BufferedReader(r);
try {
String s = inp.readLine();
char arr[] = s.toCharArray();
if(check(arr, 0, arr.length))
{
System.out.println("YES");
}
else {
System.out.println("NO");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}