- Notifications
You must be signed in to change notification settings - Fork 366
/
Copy pathStringPalindrome.java
27 lines (23 loc) · 751 Bytes
/
StringPalindrome.java
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
importjava.util.Scanner;
/*
* String is said to be a palindrome if the reverse of the string is exactly same as the given string.
*/
publicclassStringPalindrome {
publicstaticvoidmain(String[] args) {
System.out.print("Enter a string: ");
Scannerin=newScanner(System.in);
Stringstr=in.next();
System.out.println(ispali(str));
}
staticStringispali(Stringstr){
str=str.toLowerCase();
for (inti = 0; i <str.length()/2 ; i++) {
charstart=str.charAt(i);
charend=str.charAt(str.length()-1-i);
if(start!=end){
return"It is not a palindrome";
}
}
return"It is a palindrome";
}
}