Advertisement
tunerkelley

Problem 1

Feb 10th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1.  
  2. public class Problem01 {
  3.  
  4. public static void main(String[] args) {
  5. String j = "civic";
  6. System.out.println(j + (pal(j) ? " is" : " is not") + " a palindrome.");
  7. String q = "rotator";
  8. System.out.println(q + (pal(q) ? " is" : " is not") + " a palindrome.");
  9. String t = "panda";
  10. System.out.println(t + (pal(t) ? " is" : " is not") + " a palindrome.");
  11. }
  12.  
  13. public static boolean pal(String s) {
  14. if (s.length() == 0 || s.length() == 1)
  15. return true;
  16. else {
  17. if (s.charAt(0) != s.charAt(s.length() - 1))
  18. return false;
  19. else
  20. return pal(s.substring(1, s.length() - 1));
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement