给定一个字符串数组,返回该数组,其中所有字符串的长度均为偶数,并替换为空字符串。给定一个字符串数组,将所有字符串的长度均替换为空字符串
blankAllEvens({ "Hi", "there", "bob" }) => {"", "there", "bob"}
blankAllEvens({ "this", "is", "sparta!"}) => {"", "", "sparta!"}
blankAllEvens({ }) => {}
如何返回字符串? 我需要返回字符串以便为平铺打印空白空间,但现在我只是返回一个计数。 这是我的代码我认为一切正常,我只是不知道如何返回它?
public String[] blankAllEvens(String[] words) {
int cnt = 0;
for (int i=0; i<words.length; i++) {
if (words[i].substring(0, 1).equals("2")) {
cnt++;
}
}
return cnt;
}
我敢肯定'cnt'代表count,但那不是我怎么读的:) –