From 175721a63b426355274fa9e8063f762020ab8362 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Thu, 30 Jan 2020 16:55:04 -0600 Subject: R E A R R A N G E --- OLD/csci1913/Java/lab13_strap012.java | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 OLD/csci1913/Java/lab13_strap012.java (limited to 'OLD/csci1913/Java/lab13_strap012.java') diff --git a/OLD/csci1913/Java/lab13_strap012.java b/OLD/csci1913/Java/lab13_strap012.java new file mode 100644 index 0000000..8645a98 --- /dev/null +++ b/OLD/csci1913/Java/lab13_strap012.java @@ -0,0 +1,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(); + } + } +} \ No newline at end of file -- cgit v1.2.3