so basically the user enters 2 lines (CATSATONTHEMAT AT), and we need to calculate how many times the second line appears in the first line (so the answer here is 3)
this is what I still have and he keeps talking
"Exception in thread" main "java.lang.StringIndexOutOfBoundsException: row index out of range: 81223 in java.lang.String.substring (Unknown source) in practice .main (practice.java:60)"
Any help would be appreciated! I just donβt see to find where I was wrong.
String s = scan.next();
String t = scan.next();
int j= 0;
for ( int i = 0 ; i < s.length(); i++){
int k = t.length();
String newstring = s.substring(i,i+k);
if(newstring.equals(t))
j++;
}
System.out.printf("%d", j);
source
share