fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static boolean isPalindrome(String word){
  11. System.out.println("Checking "+word+" length: "+word.length());
  12. if(word.length()==0 || word.length()==1){
  13. System.out.println("Base Case");
  14. return true;
  15. } else if(word.charAt(0)==word.charAt(word.length()-1)){
  16. System.out.println("Resursive case substring(1,"+(word.length()-1)+")");
  17. return isPalindrome(word.substring(1, word.length()-1));
  18. }else {
  19. return false;
  20. }
  21. }
  22.  
  23. public static void main (String[] args) throws java.lang.Exception
  24. {
  25. isPalindrome("abba");
  26. }
  27. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
Checking abba length: 4
Resursive case substring(1,3)
Checking bb length: 2
Resursive case substring(1,1)
Checking  length: 0
Base Case