Recursive Palindrome Method
What is the output when the following program is executed?
public class Main {
public static boolean isPalindrome(String s) {
if(s.length() <= 1)
return true;
if(s.charAt(0) != s.charAt(s.length() - 1))
return false;
return isPalindrome(s.substring(1, s.length()-1));
}
public static void main(String[] args) {
System.out.println(isPalindrome("radar"));
}
}
A
radar
B
false
C
Compilation Error
D
true
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE