public class homework003{
public static void main(String[] args) {
A02 a02 = new A02();
String[] strs = {"123","456","sun","yan"};
String findstr = "sun";
System.out.println("字符串在字符串数组中的下标是" + a02.find(findstr,strs));
}
}
class A02{
public int find(String findstr,String[] strs){
//直接遍历
//findStr.equals(strs[i]) equals布尔类型 若括号内的数组定位的字符串和当前字符串相同 则返回1 错误返回0
for (int i = 0;i < strs.length;i++ ) {
if (findstr.equals(strs[i])) {
return i;//返回下标
}
}
//遍历之后还没有,则说明没有返回-1
return -1;
}
}