-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChallenge13.java
More file actions
32 lines (26 loc) · 839 Bytes
/
Challenge13.java
File metadata and controls
32 lines (26 loc) · 839 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
package challenge13;
import static org.junit.Assert.assertTrue;
import java.util.Set;
import org.junit.jupiter.api.Test;
/**
* *How to check if String is Palindrome ?(solution) For example, if the input is
* "radar", the output should be true, if input is "madam" output will be true,
* and if input is "Java" output should be false.
*/
public class Challenge13 {
public static boolean isPalindrome(String input) {
String revered = getReverse(input);
System.out.println(revered);
return input.equals(revered);
}
private static String getReverse(String input) {
if (input.length() < 2)
return input;
return getReverse(input.substring(1)) + input.charAt(0);
}
@Test
public void test() {
boolean isPalindrome = Challenge13.isPalindrome("madam");
assertTrue(isPalindrome);
}
}