public class RabinKarp {

	private static final int BASE = 101;
	private static final int MOD = 1_000_007;

	private static int hash(String pattern) {
		int hashCode = 0;
		for (int i = 0; i < pattern.length(); i++)
			hashCode += (pattern.charAt(i) * Math.round(Math.pow(BASE,
					pattern.length() - i)))
					% MOD;
		return hashCode;
	}

	private static int rabinKarp(String s, String pattern) {
		int hpattern = hash(pattern);
		int hs = hash(s.substring(0, pattern.length()));
		for (int i = 0; i < s.length() - pattern.length(); i++) {
			if (hs == hpattern)
				if (s.substring(i, i + pattern.length()).equals(pattern))
					return i;
			hs = hash(s.substring(i + 1, i + 1 + pattern.length()));
		}
		return -1;
	}

	public static void main(String[] args) {
		System.out.println(rabinKarp("ABC ABCDAB ABCDABCDABDE", "ABCDABD"));
	}

}

@@ -79,19 +79,20 @@
 c final 
-int
+long
  MOD = 1
@@ -96,16 +96,20 @@
 = 1_000_
+000_
 007;%0A%0A%09p
@@ -151,19 +151,20 @@
 rn) %7B%0A%09%09
-int
+long
  hashCod
@@ -326,16 +326,22 @@
 %09%09return
+ (int)
  hashCod

Update RabinKarp.java