korobushk

palindromeRec

Apr 20th, 2021
740
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ispalindrome;
  2.  
  3. public class App {
  4.     public static void main(String[] args) {
  5.         var result = isPalindrome("tacat");
  6. //        var result1 = isPalindrome("hola");
  7. //        var result2 = isPalindrome("amanaplanacanalpanama");
  8. //        var result3 = isPalindrome("tacat");
  9.         System.out.println(result);
  10. //        System.out.println(result1);
  11. //        System.out.println(result2);
  12.     }
  13.  
  14.     public static boolean isPalindrome(String s) {
  15.         if (s.length() == 0 || s.length() == 1) {
  16.             return true;
  17.         }
  18.         char first = s.charAt(0);           //first to end
  19.         char last = s.charAt(s.length() - 1); // end to first
  20.  
  21.         if (first != last) {
  22.             return false;
  23.         }
  24.  
  25.         return isPalindrome(s.substring(1, s.length() - 1));  
  26.  
  27.     }
  28. }
  29.  
  30.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×