I want to make a calculator in java.
I need to know that is there any way to solve a String Mathematically?
for example:
String str = "3+2*6";
and somehow I'll get:
int result = 15;
I want to make a calculator in java.
I need to know that is there any way to solve a String Mathematically?
for example:
String str = "3+2*6";
and somehow I'll get:
int result = 15;
Try this:
ScriptEngineManager mg = new ScriptEngineManager();
ScriptEngine engine = mg.getEngineByName("JavaScript");
String val = "3+2*5";
System.out.println(engine.eval(val));