In java, I am currently in the process of trying to find a way to do mathematical sums by typing in text to a JTextField, putting it into a String, and converting it to an int a
You can use the JavaScript
engine:
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
String expression = textField.getText();
System.out.println(engine.eval(expression));
Edit to allow all equations:
All you have to do now to allow things like sin, cos, tan is this:
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
String expression = textField.getText();
// Between here...
expression = expression.
replace("sin", "Math.sin").
replace("cos", "Math.cos").
replace("tan", "Math.tan").
replace("sqrt", "Math.sqrt").
replace("log", "Math.log").
replace("pi", "Math.PI");
// And so on...
System.out.println(engine.eval(foo));
So then you can do something like:
5 + 5 - 2 / 5 + sin(55) - log(20)
Anything you want.