Boolean Expression Evaluation in Java

前端 未结 10 1384
-上瘾入骨i
-上瘾入骨i 2020-12-05 16:26

I\'m looking for a relatively simpler (when compared with writing a parser) way to evaluate boolean expressions in Java, and I do not want to use the JEP library.

I

10条回答
  •  佛祖请我去吃肉
    2020-12-05 16:58

    There is a API available at http://lts.online.fr/dev/java/math.evaluator/

    Example:

    MathEvaluator m = new MathEvaluator("-5-6/(-2) + sqr(15+x)");
    m.addVariable("x", 15.1d);
    System.out.println( m.getValue() );
    

提交回复
热议问题