Skip to content

Instantly share code, notes, and snippets.

@joanmolinas
Last active August 29, 2015 14:17
Show Gist options
  • Save joanmolinas/c2f15c0afb0cf2b37fdd to your computer and use it in GitHub Desktop.
Save joanmolinas/c2f15c0afb0cf2b37fdd to your computer and use it in GitHub Desktop.
// Know if word is palindrome
// System.out.println((isPalindrome(palindrome) ? "Yes" : "No")); -> Output "Yes"
public static boolean isPalindrome(String s) {
String word = new StringBuilder(s).reverse().toString();
return word.equalsIgnoreCase(s);
}
// Know number of characters contains this word
// String word = "Palangana";
// char character = 'a';
// int number = characterOcurrence("Palangana", 'a');
// System.out.println("In the word: '"+word+"' are " + number + " '" + character + "'"); -> In the word: palangana are 4 a
public static int characterOcurrence(String s, char character) {
s = s.replaceAll("[^"+ character + "]","");
System.out.println(s);
return s.length();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment