不废话,直接上代码:Java代码
package org。galo。thread;
import java。util。Scanner;
import javax。script。Invocable;
import javax。script。
ScriptEngine;
import javax。script。ScriptEngineManager;
import javax。script。ScriptException;
public class Calculator {
private static final String WELCOME_MESSAGE = "请输入计算表达式:(或'exit'退出)";
private static final String EXIT_MESSAGE = "系统正在退出,请稍后";
private static final String QUIT_MESSAGE = "感谢您的使用,再见!";
private static final String ERROR_MESSAGE = "[表达式语法错误]请输入:(或'exit'退出)";
public static void main(String[] args) {
sayWelcome();
main();
}
public static void main() {
Scanner scanner = new Scanner(System。
in);
println(WELCOME_MESSAGE);
while(scanner。hasNext()){
String exp = scanner。next();
long startTime = System。currentTimeMillis();
if("exit"。
equals(exp)){
doExit();
return;
}
String result = evalJS(exp);
if(result == null){
continue;
}。
全部