forked from Rupangkan/itssubhamroy.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGFG.java
More file actions
39 lines (32 loc) · 924 Bytes
/
GFG.java
File metadata and controls
39 lines (32 loc) · 924 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
//// Java program to check whether a
// string is a Palindrome using recursion
import java.io.*;
class GFG {
public static boolean isPalindrome(int i, int j,
String A)
{
// comparing the two pointers
if (i >= j) {
return true;
}
// comparing the characters on those pointers
if (A.charAt(i) != A.charAt(j)) {
return false;
}
// checking everything again recursively
return isPalindrome(i + 1, j - 1, A);
}
public static boolean isPalindrome(String A)
{
return isPalindrome(0, A.length() - 1, A);
}
public static void main(String[] args)
{
// Input string
String A = "geeks";
// Convert the string to lowercase
A = A.toLowerCase();
boolean str = isPalindrome(A);
System.out.println(str);
}
}