怎么找到字符串指定的字
Java有这些商品"【聚划算】中华广式五仁月饼","【天天特价】纯黑格子衬衫","【聚划算】格兰仕全自动洗衣机 ,"【天天特价】海鲜即食鱿鱼","【双十一特价】智能充电器","【天天特价】,多功能浴霸","【聚划算】20倦手抽纸" "【双十一特价】16g手机内存卡",找到以【聚划算】开头的商品名称 package exercisement;public class Main {
public static void main(String[] args) {
String[] strs = {"【聚划算】中华广式五仁月饼","【天天特价】纯黑格子衬衫","【聚划算】格兰仕全自动洗衣机" ,"【天天特价】海鲜即食鱿鱼","【双十一特价】智能充电器","【天天特价】,多功能浴霸","【聚划算】20倦手抽纸","【双十一特价】16g手机内存卡"};
for(String str : strs) {
//如果开头是"【聚划算】"
if(str.indexOf("【聚划算】") == 0) {
System.out.println(str);
}
}
}
}
如果我想优化一下就是从键盘上输入要查找的类型,然后输出这些类型
页:
[1]