Advertisement
DulcetAirman

evaluation

Sep 12th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement