For this code, all I want to do is split the original string into words by spaces and use regex to return the words that are not y, 4, !, or ?
However, I'm not sure why this isn't working:
public static void main (String[] args) {
System.out.println(makeWords("y are you not 4 !?"));
//should return string "are you not"
}
public static String makeWords (String str) {
String[] word = str.split(" ");
//make array of words
String result = "";
for (int i = 0; i < word.length; i++) {
if (word[i].matches("[^y4!?]")) {
String str = word[i];
result += str;
}
}
return result;
}
}