public static int indexOf(char[] chs, int startIndex, char ch)
{
}
*/
class IndexOfTest
{
public static void main(String[] args)
{
char[] chs = new char[]{'a','s','d','f','g','h'};
int x = indexOf(chs,'d');
System.out.println("第一次出现的位置是:"+x);
int y = indexOf(chs,2,'f');
System.out.println("第一次出现的位置是:"+y);
}
public static int indexOf(char[] chs, char ch)
{
//标记,判断是否找到指定元素
int temp=-1;
//遍历来配对
for(int i=0;i<chs.length;i++)
{
if(chs[i] == ch)
{
temp=i;
}
}
return temp;
}
public static int indexOf(char[] chs, int startIndex, char ch)
{