diff --git a/src/main/java/io/zipcoder/StringsAndThings.java b/src/main/java/io/zipcoder/StringsAndThings.java index 073467a..5cfec4c 100644 --- a/src/main/java/io/zipcoder/StringsAndThings.java +++ b/src/main/java/io/zipcoder/StringsAndThings.java @@ -1,6 +1,8 @@ package io.zipcoder; +import java.util.Locale; + /** * @author tariq */ @@ -11,38 +13,73 @@ public class StringsAndThings { * but not the 'y' in "yellow" (not case sensitive). We'll say that a y or z is at the end of a word if there is not an alphabetic * letter immediately following it. (Note: Character.isLetter(char) tests if a char is an alphabetic letter.) * example : countYZ("fez day"); // Should return 2 - * countYZ("day fez"); // Should return 2 - * countYZ("day fyyyz"); // Should return 2 + * countYZ("day fez"); // Should return 2 + * countYZ("day fyyyz"); // Should return 2 */ - public Integer countYZ(String input){ - return null; + public Integer countYZ(String input) { + int result = 0; + String[] words = input.split(" "); + for (String word : words + ) { + if (word.endsWith("y") || word.endsWith("z")) { + result += 1; + } + + } + return result; } /** * Given two strings, base and remove, return a version of the base string where all instances of the remove string have * been removed (not case sensitive). You may assume that the remove string is length 1 or more. * Remove only non-overlapping instances, so with "xxx" removing "xx" leaves "x". - * + *
* example : removeString("Hello there", "llo") // Should return "He there" - * removeString("Hello there", "e") // Should return "Hllo thr" - * removeString("Hello there", "x") // Should return "Hello there" + * removeString("Hello there", "e") // Should return "Hllo thr" + * removeString("Hello there", "x") // Should return "Hello there" */ - public String removeString(String base, String remove){ - return null; + public String removeString(String base, String remove) { + String result = ""; + result = base.replace(remove, ""); + return result; } /** * Given a string, return true if the number of appearances of "is" anywhere in the string is equal * to the number of appearances of "not" anywhere in the string (case sensitive) - * + *
* example : containsEqualNumberOfIsAndNot("This is not") // Should return false
- * containsEqualNumberOfIsAndNot("This is notnot") // Should return true
- * containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
+ * containsEqualNumberOfIsAndNot("This is notnot") // Should return true
+ * containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
*/
- public Boolean containsEqualNumberOfIsAndNot(String input){
- return null;
+ public Boolean containsEqualNumberOfIsAndNot(String input) {
+ Boolean result = false;
+ String[] inputSplitIntoLetters = input.split("");
+ int countOfIs=0;
+ int countOfNot=0;
+ for(int i=0;i