JEP是java數(shù)學(xué)解析器的一個(gè)開源工具,解析并計(jì)算與數(shù)學(xué)運(yùn)算相關(guān)的字符串的一個(gè)類庫(kù),是java數(shù)學(xué)解析器的一個(gè)開源工具,提供第三方的jar包只要將jar包放到lib目錄下即可使用
簡(jiǎn)單示例:
import com.singularsys.jep.Jep;
import com.singularsys.jep.JepException;
public class SimpleExample {
public static void main(String[] args) {
Jep jep = new Jep();
//一個(gè)數(shù)學(xué)表達(dá)式
String exp = "((a+b)*(c+b))/(c+a)/b";
//給變量賦值
jep.addVariable("a", 10);
jep.addVariable("b", 10);
jep.addVariable("c", 10);
try {
//執(zhí)行
jep.parse(exp);
Object result = jep.evaluate();
System.out.println("計(jì)算結(jié)果: " + result);
} catch (JepException e) {
System.out.println("An error occured: " + e.getMessage());
}
}
}
具體更復(fù)雜的操作可以參看下載的zip中\(zhòng)doc\html\index.html
Jep is a Java library for parsing and evaluating mathematical expressions. With this package you can allow your users to enter an arbitrary formula as a string, and instantly evaluate it. Jep supports user defined variables, constants, and functions. A number of common mathematical functions and constants are included.
參考資料:http://www.singularsys.com/jep/doc/html/index.html