rapperwith1p
Gawd
- Joined
- Oct 23, 2005
- Messages
- 670
Code:
def hash(s,M) # Returns integer 0..M-1
y = 0
s.each { |c| y = y * 127 + Integer(c) }
return y % M
end
Need help converting this chunk of code in Ruby to Java.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
def hash(s,M) # Returns integer 0..M-1
y = 0
s.each { |c| y = y * 127 + Integer(c) }
return y % M
end
public class TestMe {
public static int hash(final String s, final int m) {
return java.lang.Integer.parseInt(s) % m;
}
public static void main(String args[]) {
System.out.println(hash("12345678", 8));
}
}