-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringPalindrome.java
More file actions
32 lines (25 loc) · 1005 Bytes
/
StringPalindrome.java
File metadata and controls
32 lines (25 loc) · 1005 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
import java.util.Scanner;
//This code is not working as expected. please review
public class StringPalindrome {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Please enter your String : ");
String str = scan.next();
stringPalindrome(str);
}
public static void stringPalindrome(String str) {
String actualString = str;
StringBuffer reverseString = new StringBuffer();
for(int i = actualString.length()-1;i>=0;i--){
reverseString = reverseString.append(actualString.charAt(i));
}
System.out.println("reverse string is : " + reverseString);
System.out.println("acutal string is :" + actualString);
if(actualString.equals(reverseString.toString())) {
System.out.println("It is a string palindrome");
}
else{
System.out.println("Not a String Palindrome");
}
}
}