Your Computer Science Resource

Posts Tagged ‘mathematical string’

Jan
12th

HOW-TO: Evaluate a Mathematical String Using ScriptEngine

Suppose you have a String containing some mathematical operation(s). For example, we need to perform the following calculation, but for various reasons, the data type is a String: (10*(34+92)-23)/4. Rather than figuring out ways to parse it (e.g. split or some fancy regex), we can use Java’s ScriptEngine to evaluate the function as is.

(more…)