-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringPalindrome.java
More file actions
34 lines (24 loc) · 906 Bytes
/
StringPalindrome.java
File metadata and controls
34 lines (24 loc) · 906 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 StringPalindrome {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//Checks whether the entered string is palindrome or not (using recursive function).
//Case Sensitive.
//Will not accept string with spaces.
//Returns "true" if string is palindrome else returns "false".
String string;
System.out.print("Enter a string : ");
string = scanner.next();
palindrome(string,string.length(),0);
System.out.println(palindrome(string,string.length(),0));
}
static boolean palindrome(String string, int n, int i){
if(i>=n/2){
return true;
}
if(string.charAt(i)!=string.charAt(n-i-1)){
return false;
}
return palindrome(string,n,i+1);
}
}