Created
April 2, 2020 20:27
-
-
Save Camshaft54/2480c9056369cd9f28412e824c40c29c to your computer and use it in GitHub Desktop.
starOut Solution CodingBat
This file contains 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
public String starOut(String str) { | |
String newStr = ""; | |
int[] stars = new int[str.length()]; | |
for (int i = 0; i < str.length(); i++) { | |
if (str.substring(i, i+1).equals("*")) { | |
if (i != 0) { | |
stars[i-1] = 1; | |
} | |
stars[i] = 1; | |
if (i + 1 < stars.length) { | |
stars[i+1] = 1; | |
} | |
} | |
} | |
for (int j = 0; j < str.length(); j++) { | |
if (stars[j] == 0) | |
newStr += str.substring(j, j + 1); | |
} | |
return newStr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment