I know there are answers online but I don't want to copy them. I have started with most of it but do not know how to take out the spaces and convert back to a string? Also if you guys have a better solution feel free to provide that. Thank You. Please no Regex code.
public static String starOut(String str) {
char[] array = str.toCharArray();
for(int i = 0; i < array.length; i++) {
if(array[i] == '*' && i != 0) {
if(array[i - 1] != '*') {
array[i - 1] = ' ';
}
if(array[i + 1] != '*') {
array[i + 1] = ' ';
}
}
//Rest of Code...
if()
}
return str;
}
Aucun commentaire:
Enregistrer un commentaire