SHARE
TWEET

evaluation

DulcetAirman Sep 12th, 2017 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ch.fhnw.claudemartin;
  2.  
  3. import javax.script.ScriptEngine;
  4. import javax.script.ScriptEngineManager;
  5. import javax.script.ScriptException;
  6.  
  7. class SomeClass {
  8.   public static void main(final String[] args) throws ScriptException {
  9.     final ScriptEngine ecma = new ScriptEngineManager()
  10.         .getEngineByName("nashorn");
  11.     final String go[] = { "1+2", "3+6", "4+5" };
  12.  
  13.     for (final String x : go) {
  14.       final Object value = ecma.eval(x);
  15.       if (value instanceof Number) {
  16.         final int i = ((Number) value).intValue();
  17.         System.out.printf("integer: %d%n", i);
  18.       } else
  19.         System.out.printf("non-numeric: %s%n", value);
  20.     }
  21.   }
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top