-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw_f_palindrome.java
More file actions
34 lines (30 loc) · 992 Bytes
/
hw_f_palindrome.java
File metadata and controls
34 lines (30 loc) · 992 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
import java.util.Scanner;
public class hw_f_palindrome{
static boolean checkPalindrome(String str, int s, int e) {
if (s == e)
return true;
if ((str.charAt(s)) != (str.charAt(e)))
return false;
if (s < e + 1)
return checkPalindrome(str, s + 1, e - 1);
return true;
}
static boolean isPalindrome(String str)
{
int n = str.length();
if (n == 0)
return true;
return checkPalindrome(str, 0, n - 1);
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the String :");
String str = sc.nextLine();
if (isPalindrome(str))
System.out.println(str+" is palindrome");
else
System.out.println(str+ " is not a palindrome");
sc.close();
}
}