palindrome.java 992 B

123456789101112131415161718192021222324252627282930313233
  1. import java.util.Scanner;
  2. public class palindrome {
  3. public static boolean isPalindrom(String str, boolean firstRun) {
  4. System.out.println("Aufruf mit: " + str);
  5. int length = str.length();
  6. if (firstRun && length == 0) {
  7. System.out.println("Warning: Zero length strings are not" +
  8. "considered palindromes");
  9. return false;
  10. }
  11. if (length == 0)
  12. return true;
  13. else if (length == 1)
  14. return false;
  15. else if (str.charAt(0) == str.charAt(length-1))
  16. return isPalindrom(str.substring(1, length-1), false);
  17. else
  18. return false;
  19. }
  20. public static void main(String[] args) {
  21. Scanner scanner = new Scanner(System.in);
  22. System.out.printf(" >>> ");
  23. String input = scanner.nextLine();
  24. scanner.close();
  25. boolean bool = isPalindrom(input, true);
  26. System.out.println(" = " + bool);
  27. }
  28. }