
HashingAbrahamLincoln
By: a guest on
May 8th, 2012 | syntax:
Java | size: 0.66 KB | hits: 15 | expires: Never
package Lesson57;
public class HashingAbrahamLincoln {
/**
* @param args
*/
public static int hashCode(String s){
final int TABLE_SIZE = 180;
int hash = 0;
s = s.toUpperCase();
hash += s.charAt(0) * 1000;
hash += s.charAt(1) * 100;
hash += s.charAt(2) * 10;
hash += s.charAt(s.length()-1);
return hash % TABLE_SIZE;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String arr[] = new String[] {
"Bush, George",
"Clinton, Bill",
"Lincoln, Abraham",
"Washington, George"
};
for(String x : arr){
System.out.println(x + ">>>" + hashCode(x));
}
}
}