Problem:
Write a recursive method that checks if a String is a palindrome.
Output:
Not needed.
Solution:
import java.util.Scanner; public class ProblemC { public static boolean isPalindrome(String s) { if(s.length() == 0 || s.length() == 1) return true; if(s.charAt(0) == s.charAt(s.length()-1)) return isPalindrome(s.substring(1, s.length()-1)); return false; } }
No comments :
Post a Comment