Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ch.fhnw.claudemartin;
- import javax.script.ScriptEngine;
- import javax.script.ScriptEngineManager;
- import javax.script.ScriptException;
- class SomeClass {
- public static void main(final String[] args) throws ScriptException {
- final ScriptEngine ecma = new ScriptEngineManager()
- .getEngineByName("nashorn");
- final String go[] = { "1+2", "3+6", "4+5" };
- for (final String x : go) {
- final Object value = ecma.eval(x);
- if (value instanceof Number) {
- final int i = ((Number) value).intValue();
- System.out.printf("integer: %d%n", i);
- } else
- System.out.printf("non-numeric: %s%n", value);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement