I want the sub-array array has been tested in main array. but i get error.
The test I'm doing is right or need to add more conditions?
Finally, I need to print the index of the main array, in which sub-string begins.
Example to answer:
String m="cd e";
String n="abcd efghi";
print>>>> 2(the index in n String)
the error:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException:
String index out of range: 4
at java.lang.String.charAt(Unknown Source)
at test1.main(test1.java:10)
The code:
String m="cd e";
String n="abcd efghi";
for (int i = 0; i < m.length(); i++) {
for (int j = 0; j < n.length(); j++) {
if(m.charAt(j)==n.charAt(i) )
if(m.charAt(j+1)==n.charAt(i+1))
System.out.println(i);
}
}
thank's.
iseems to be iterator formandjforn, so why are you usingiforn? (you should name your variables more reasonably, eveni1i2n1n2would cause less confusion). (2) what value willi+1have wheniwill be equal tom.length-1? Is there anycharAtat position pointed by that value?