1

I have searched how to convert string "4+5" to math expression and i only found that i should use ScriptEngine but when i import the library in android studio it doesn't seem to work. Can you suggest any other ideas which would be good way how to convert string to math expression?

I used fro example this question and this is their code:

import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;

public class Test {
  public static void main(String[] args) throws Exception{
    ScriptEngineManager mgr = new ScriptEngineManager();
    ScriptEngine engine = mgr.getEngineByName("JavaScript");
    String foo = "40+2";
    System.out.println(engine.eval(foo));
    } 
}
Community
  • 1
  • 1

0 Answers0