Last active
August 29, 2015 14:17
-
-
Save joanmolinas/c2f15c0afb0cf2b37fdd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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