public int search(String txt){
  int m=pat.length();
  int n=txt.length();
  int skip;
  for (int i=0; i <= n - m; i+=skip) {
    skip=0;
    for (int j=m - 1; j >= 0; j--) {
      if (pat.charAt(j) != txt.charAt(i + j)) {
        skip=Math.max(1,j - right[txt.charAt(i + j)]);
        break;
      }
    }
    if (skip == 0)     return i;
  }
  return n;
}

public int search ( String txt ) { int m = pat . length ( ) ; int n = txt . length ( ) ; int skip ; for ( int i = 0 ; i <= n - m ; i += skip ) { skip = 0 ; for ( int j = m - 1 ; j >= 0 ; j -- ) { if ( pat . charAt ( j ) != txt . charAt ( i + j ) ) { skip = Math . max ( 1 , j - right [ txt . charAt ( i + j ) ] ) ; break ; } } if ( skip == 0 ) return i ; } return n ; }
returns the index of the first occurrrence of the pattern string in the text string .
