/** * ClassName: JavaScriptTest * Author: * Description:TODO * Date:2022-05-22 22:26 * Version: V1.0 **/ //测试 import java.util.ArrayList; import java.util.List; public class JavaScriptTest { /** * @param args */ public static void main(String[] args) { String gs= "(B+D-(A-C)*A)/F"; List<MapJ> all = new ArrayList<MapJ>(); all.add(new MapJ("A","2")); all.add(new MapJ("B","3")); all.add(new MapJ("C","4")); all.add(new MapJ("D","5")); all.add(new MapJ("F","24")); JavaScript js = new JavaScript(); Double d = js.getMathValue(all, gs); if(d==null){ System.out.println(" 无法计算这个表达式 "); }else{ System.out.println(d*100+"%"); } gs= "1*6+Math.sqrt(4)+Math.pow(2,3)"; System.out.println(gs+ "= "+js.getMathValue(gs)); } }