Created
February 19, 2016 19:30
-
-
Save kfarst/81a8c0cb8a26ad44935b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
import org.junit.*; | |
import org.junit.runner.*; | |
public class Solution { | |
public static class PalindromeTester { | |
public boolean isPalindrome( final String input ) { | |
StringBuilder strb = new StringBuilder(); | |
for (int i = 0; i<input.length(); i++) { | |
if (input.charAt(i) != ' ') { | |
strb.append(input.charAt(i)); | |
} | |
} | |
int strlength = strb.length(); | |
StringBuilder str = new StringBuilder(); | |
for (int i=strlength-1; i>=0; i--) { | |
str.append(strb.charAt(i)); | |
} | |
// System.out.println(str + "--" + input); | |
if (str.toString().equals(strb.toString())) { | |
return true; | |
} else { | |
return false; | |
} | |
// String strrev = input.reverse(); | |
// return true; | |
// Palindrome code here | |
} | |
} | |
@Test | |
public void testPalindromes() { | |
PalindromeTester tester = new PalindromeTester(); | |
Assert.assertFalse(tester.isPalindrome("sonnosk")); | |
Assert.assertTrue(tester.isPalindrome("kay ak")); | |
Assert.assertFalse(tester.isPalindrome("c anucks")); | |
// Palindrome tests here | |
} | |
public static void main(String[] args) { | |
/* | |
* 1) Write a function that returns true if a string is a palindrome | |
* - Palindrome: a word, phrase, or sequence that reads the same backward | |
* as forward, e.g., madam or nurses run. | |
* - Palindromes to test are: | |
* "sonnosk" | |
* "kay ak" | |
* "c anucks" | |
* Solution s = new Solution(); | |
*/ | |
JUnitCore.main("Solution"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment