Skip to content

all tests passed #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 52 additions & 7 deletions src/main/java/io/zipcoder/StringsAndThings.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,22 @@ public class StringsAndThings {
* countYZ("day fyyyz"); // Should return 2
*/
public Integer countYZ(String input){
return null;
int count = 0; //set count to 0
String[] splitString = input.split(" "); // create new string array and split it at space

for (int i = 0; i < splitString.length; i++){
String splitWords = splitString[i]; // set word at index to splitWords
int wordLength = splitWords.length(); //take length of words to find end
char lastChar = splitWords.charAt(wordLength-1); //lastChar
if (lastChar == 'y' || lastChar == 'z'){
count++;
}

}



return count;
}

/**
Expand All @@ -28,7 +43,10 @@ public Integer countYZ(String input){
* removeString("Hello there", "x") // Should return "Hello there"
*/
public String removeString(String base, String remove){
return null;
String newString = base.replaceAll(remove, ""); //use the remove strings and replaced all matching in base string that matched
return newString;


}

/**
Expand All @@ -40,7 +58,21 @@ public String removeString(String base, String remove){
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
*/
public Boolean containsEqualNumberOfIsAndNot(String input){
return null;
//need count of is to compare to not
//need count of not to compare to is
//need to iterate thru string
//search for is and not
//return true or false if count is equal

int isCount = 0;
int notCount = 0;
for (int i = 0; i < input.length()-1; i++) {
if (input.charAt(i) == 'i'&& input.charAt(i+1) == 's'){
isCount++;
} if (input.charAt(i) == 'n' && input.charAt(i+1) == 'o' && input.charAt(i+2) == 't'){
notCount++;
}
} return isCount == notCount;
}

/**
Expand All @@ -50,11 +82,15 @@ public Boolean containsEqualNumberOfIsAndNot(String input){
* gHappy("xxgxx") // Should return false
* gHappy("xxggyygxx") // Should return false
*/
public Boolean gIsHappy(String input){
return null;
public Boolean gIsHappy(String input) {
for (int i = 0; i < input.length(); i++) { //stop forgetting its length()!! for loop to iterate thru string
// //if the char at current index i is g and input at next index is g return true
if (input.charAt(i) == 'g' && input.charAt(i + 1) == 'g') {
return true;
}
} return false; //forgot return value for false. if g is happy return true, if not string will return false
}


/**
* We'll say that a "triple" in a string is a char appearing three times in a row.
* Return the number of triples in the given string. The triples may overlap.
Expand All @@ -63,6 +99,15 @@ public Boolean gIsHappy(String input){
* countTriple("a") // Should return 0
*/
public Integer countTriple(String input){
return null;
int count = 0;
for (int i = 1; i < input.length()-1; i++) { //had to start index at 1 to pass test 2
if (input.charAt(i) == input.charAt(i+1) && input.charAt(i) == input.charAt(i-1)){
count++;
}

}


return count;
}
}
Binary file added target/classes/io/zipcoder/StringsAndThings.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.