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.  
  11. public static Boolean isPalindrome(String str) {
  12. int n = str.length();
  13. for( int i = 0; i < n/2; i++ ) {
  14. if (str.charAt(i) != str.charAt(n-i-1)) return false;
  15. }
  16. return true;
  17. }
  18.  
  19. public static boolean isPalindrome1(String str) {
  20. return str.equalsIgnoreCase(new StringBuilder(str).reverse().toString());
  21. }
  22.  
  23.  
  24. public static void main (String[] args) throws java.lang.Exception
  25. {
  26.  
  27. System.out.println(isPalindrome("sara"));
  28. System.out.println(isPalindrome("ana"));
  29.  
  30. System.out.println(isPalindrome1("sara"));
  31. System.out.println(isPalindrome1("Ana"));
  32. }
  33. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
false
true
false
true