输入:输任意入字符串数组S[ ],即主串;
输入任意字符串数组T[ ],即子串;
输出:返回字符串数组T[ ]在字符串数组S[ ]中的的相对位置(只需输出 T [ ]的首字母位置);
(由于输入的字符主串S[ ] 、子串T[ ]是任意的,所以会有多种运行结果)
请各位高手解答:

解决方案 »

  1.   

    楼主,你要判断的究竟是字符串还是字符串数组啊
    怎么感觉你要的是字符串而 不是字符串数组字符串的话直接indexof就ok了
      

  2.   

    楼主,你想说的是这样的数组吗?
    String[] s = {"T","e","s","t"};
    String[] t = {"e","s"};
      

  3.   

    如果是这样的话,可以将两个数组分别拼成一个字符串,将t拼成的字符串到s拼成的字符串中去indexOf就ok了
      

  4.   

    String[] s = {"Test","hello","china","t"};
    String[] t = {"hello","china"};
    这个意思把,求hello china在S[]中出现的位置可否写个代码看看呢
      

  5.   

    private static int indexOf(String[] S , String[] T)
    {
    int nIndex = -1;
    if(T!=null && S!=null && T.length!=0 && S.length !=0){

    int nowIndex = -1;
    for(int n =0;n<S.length;n++)
    {
    if (S[n].equals(T[nowIndex+1]))
    nowIndex += 1;
    if(nowIndex == T.length-1)
    {
    nIndex = n - nowIndex;
    break;
    }
    }
    }
    return nIndex;
    }
      

  6.   

    public static void main(String[] args) throws Exception
    {
    String[] s1 = {"Test","hello","china","t"};
    String[] t1 = {"hello","china"};
    System.out.println(indexOf(s1,t1));
    //得到显示1String[] s = {"Test","hello","china","t"};
    String[] t = {""};
    System.out.println(indexOf(s,t));
    //得到显示-1
    }