public class shuzuhe {
public static void main(String[] args) {
// TODO Auto-generated method stub
String []score={"a","abc","a"};//记得加引号
String chuan="a";
int b=0;
for(int i=0;i<score.length;i++){
if(chuan==score[i]){
b=1;
break; //记得break,直接跳出循环
}
}
if(b==1){
System.out.print("存在");
}
else if(b!=1)
System.out.print("不存在");
}
}
本文提供了一个简单的Java程序示例,展示了如何在一个字符串数组中查找特定的字符串,并判断该字符串是否存在。通过遍历数组并使用条件判断语句,程序能够有效地确定目标字符串是否存在于数组中。
1555

被折叠的 条评论
为什么被折叠?



