原理
手动建立一个映射,其实就是手动完成了散列映射。然后暴力查表就完事儿了嗷
卦限 | 符号特征(1:正0:负) | 存储位置 |
---|---|---|
1 | 111 | 7 |
2 | 011 | 3 |
3 | 001 | 1 |
4 | 101 | 5 |
5 | 010 | 2 |
6 | 110 | 6 |
7 | 000 | 0 |
8 | 100 | 4 |
源码留念
public class App {
private static Scanner scanner = new Scanner(System.in);
final private static String mapping = "73628451";
private static String typing = null;
private static char result = '0';
private static String msg = null;
public static void main(String[] args) {
for (;;) {
try {
start();
} catch (Exception e) {
// TODO: handle exception
System.out.println("error typing!");
}
}
}
private static void start() {
input();
action();
display();
}
private static void display() {
System.out.println(msg);
}
private static void action() {
if (typing.equals("c")) {
msg = "exit procedure!";
display();
System.exit(0);
}
int t = Integer.parseInt(typing, 2);
result = mapping.charAt(t);
msg = "the result=" + result;
}
private static void input() {
// TODO Auto-generated method stub
msg = "input coordinate feature or opreation code:";
display();
if (scanner.hasNextLine()) {
typing = scanner.nextLine();
}
}
}