We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c8e07fd commit 602aa74Copy full SHA for 602aa74
java/java-string-reverse/Solution.java
@@ -0,0 +1,33 @@
1
+import java.util.*;
2
+
3
+public class Solution {
4
5
+ public static void main(String[] args) {
6
+ Scanner sc = new Scanner(System.in);
7
+ String word = sc.next();
8
+ sc.close();
9
10
+ System.out.println(isPalindrome(word) ? "Yes" : "No");
11
12
+ }
13
14
+ private static boolean isPalindrome(String word) {
15
+ return word.equals(reverse(word));
16
17
18
+ // Copied from
19
+ // https://www.baeldung.com/java-reverse-string
20
+ private static String reverse(String word) {
21
+ if (word == null) {
22
+ return word;
23
24
25
+ String output = "";
26
27
+ for (int i = word.length() - 1; i >= 0; i--) {
28
+ output = output + word.charAt(i);
29
30
31
+ return output;
32
33
+}
0 commit comments