aboutsummaryrefslogtreecommitdiffstats
path: root/csci1913/Java/lab13_strap012.java
blob: 8645a98112514cb17ee7661bc7b843de681ce6a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Test 
{ 
  private static final String [] reserved = 
   { "and", 
     "begin", 
     "define", 
     "do", 
     "else", 
     "end", 
     "if", 
     "not", 
     "or", 
     "return", 
     "then", 
     "while" }; 
 
  private static int hash(String name) 
  { 
    return ((name.charAt(0) + name.charAt(name.length()-1)) * name.length()) % 255;
  } 
 
  public static void main(String [] args) 
  { 
    for (int index = 0; index < reserved.length ; index += 1) 
    { 
      System.out.print("h(\"" + reserved[index] + "\") = "); 
      System.out.print(hash(reserved[index])); 
      System.out.println(); 
    } 
  } 
}