Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Embbed Javascript on Java6 code, this code as a calculator on the first parameter
import javax.script.*;
class Eval {
static ScriptEngineManager manager = new ScriptEngineManager();
static ScriptEngine engine= manager.getEngineByName("js");
public static void main(String args[]) {
public static String calc(String line) {
try {
engine.eval("i="+line); // calculate expression
catch(ScriptException se) {return("ERROR"); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment