计算公式

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

/**
 * 计算公式
 * @author RuiLin.Xie - xKF24276
 *
 */
public class ScriptEngineTest
{
	public static void main(String[] args)
	{
		ScriptEngineManager sem = new ScriptEngineManager();
		ScriptEngine se = sem.getEngineByName("js");
		try
		{
			System.out.println(se.eval("1+2*(3+4)").toString());
		}
		catch (ScriptException e)
		{
			e.printStackTrace();
		}
	}

}

你可能感兴趣的:(java)