How to evaluate string that have exponential

倖福魔咒の 提交于 2019-12-02 06:51:52

^ is the XOR operand, your string means 2 XOR 3 + 4, which in facts evaluates to 1 + 4.

You have to use

Math.pow(2,3) + 4

This is my code:

System.out.println(engine.eval("Math.pow(2,3) + 4"));

Output:

12.0
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!