Posted By

mscribellito on 03/15/11


Tagged


Versions (?)

Palindrome


 / Published in: Java
 

  1. public class Palindrome {
  2.  
  3. /**
  4. * @param args
  5. */
  6. public static void main(String[] args) {
  7.  
  8. if (palindrome("Cabbbac"))
  9. System.out.println("bingo");
  10. else
  11. System.out.println("nope");
  12.  
  13. }
  14.  
  15. public static boolean palindrome(String input) {
  16.  
  17. input = input.toLowerCase();
  18.  
  19. for (int i = 0; i < input.length() / 2; i++) {
  20.  
  21. char c1 = input.charAt(i);
  22. char c2 = input.charAt(input.length() - i - 1);
  23.  
  24. if (c1 != c2) return false;
  25.  
  26. }
  27.  
  28. return true;
  29.  
  30. }
  31.  
  32. }

Report this snippet  

You need to login to post a comment.