codingbat

String-2 > sameStarChar 不会做

CodingBat
String-2 > sameStarChar

https://codingbat.com/prob/p194491

Returns true if for every ‘*’ (star) in the string, if there are chars both immediately before and after the star, they are the same.

如果string里面的每一个“*”,前面后面都有相同的char,就返回true?

public boolean sameStarChar(String str) {
for (int i=1;i<str.length()-1; i++){
if(str.charAt(i)==’*’ && String.valueOf(str.charAt(i-1)).equals(String.valueOf(str.charAt(i+1)))) {
return true;
}
}
return false;
}

所以这是什么意思??不懂。

笔记