-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheckPalindrome.java
More file actions
34 lines (29 loc) · 941 Bytes
/
Copy pathcheckPalindrome.java
File metadata and controls
34 lines (29 loc) · 941 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
package main.java;
/**
* Created by neeraj.bhatnagar on 1/18/2017.
*/
public class checkPalindrome {
public static void main(String[] args) {
/*String var = "ABB";
StringBuffer rev = new StringBuffer(var).reverse();
String strRev = rev.toString();
if(var.equalsIgnoreCase(strRev)){
System.out.println("String is palindrome");
} else {
System.out.println("String is not palindrome");
}*/
//Store varibael in string.
String var = "ABB";
// Create mutable(Changeable) string.
StringBuffer sb = new StringBuffer(var);
// Reverse Sting buffer
StringBuffer rev = sb.reverse();
//Convert to string.
String strRev = rev.toString();
if(var.equalsIgnoreCase(strRev)){
System.out.println("Palindrome");
}else{
System.out.println("No Palindrome");
}
}
}