-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStringReverseCheck.java
47 lines (42 loc) · 1.24 KB
/
StringReverseCheck.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.io.*;
import java.util.*;
public class StringReverseCheck {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String A=sc.next();
StringBuffer A1 = new StringBuffer(A);
StringBuffer ans = new StringBuffer();
/* Enter your code here. Print output to STDOUT. */
for(int i = A.length()-1; i >= 0;i--)
{
ans.append(A.charAt(i));
}
// System.out.println(A);
// System.out.println(A1);
// System.out.println(ans);
if(A1.compareTo(ans) == 0)
{
System.out.println("Yes");
}
else
{
System.out.println("No");
}
}
}
//another sol--->
//System.out.println( A.equals( new StringBuilder(A).reverse().toString()) ? "Yes" : "No" );
//another 1-->
// Scanner sc=new Scanner(System.in);
// String A=sc.next();
// boolean valid = true;
//
// for(int i = 0; i < (A.length() / 2); i++) {
// if(A.charAt(i) != A.charAt((A.length() - 1) - i)) {
// valid = false;
// break;
// } // end if
// } // end for(i)
//
// if(valid) System.out.println("Yes");
// else System.out.println("No");