public
class
apples{
public
static
void
main(String[] args){
String[]
words = {"funk",
"chunk","furry",
"bacon"};
//startsWith
for(String
w : words){
if(w.startsWith("fu"))
→ 哪個字是fu開始
System.out.println(w
+ " starts with fu");
}
//endWith
for(String
w : words){
if(w.endsWith("unk"))
→ 哪個字是unk結束
System.out.println(w
+ " end with unk");
}
}
}
這是運行時的結果:
funk
starts with fu
furry
starts with fu
funk
end with unk
chunk
end with unk
沒有留言:
張貼留言