Skip to content

Commit d06abd6

Browse files
committed
Return yes if palindrome
1 parent 360ee46 commit d06abd6

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Java/Strings/Reverse.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Given a string AA, print "Yes" if it is a palindrome, print "No" otherwise. The strings will consist lower case english letters only. The strings will have at most 50 characters.
3+
4+
Some examples of palindromes are "madam", "anna", "reviver".
5+
*/
6+
7+
import java.io.*;
8+
import java.util.*;
9+
10+
public class Solution {
11+
12+
public static void main(String[] args) {
13+
14+
Scanner sc=new Scanner(System.in);
15+
String A=sc.next();
16+
Solution s = new Solution();
17+
if (s.reverse(A)) {
18+
System.out.print("Yes");
19+
}
20+
else {
21+
System.out.print("No");
22+
}
23+
}
24+
25+
public boolean reverse(String n) {
26+
boolean a = false;
27+
String x = "";
28+
for (int i = n.length()-1; i >= 0; i--) {
29+
x=x.concat(""+n.charAt(i));
30+
}
31+
if (n.equals(x)) {
32+
a = true;
33+
}
34+
return a;
35+
}
36+
}

0 commit comments

Comments
 (0)