支持运算符:+-*/%><][!|&=;其中]表示大于等于、[表示小于等于、!表示不等于、|表示或、&表示与、=表示是否等于
支持函数:sqrt,square, ceil,sin,cos,asin,,log,exp具体含义见calFunction代码
表达式计算组件源码:
import ;
import .*;
public class BaseExpression {
public static String OPTS = "+-*/%><][!|&=#";
public Object calculate(String expression) throws ExpressionException{
try
{
Stack Opts = new Stack();
Stack Values = new Stack();
String exp = expression + "#";
int nCount = (), nIn, nOut, nTemp;
("#");
String temp = "", optOut = "", optIn = "", value1 = "", value2 = "",
optTemp = "", opt = "", temp1 = "";
int nFun = 0;
boolean isFun = false;
for (int i = 0; i < nCount; ) {
nTemp = 0;
opt = (i, i + 1);
isFun = false;
temp1 = "";
while (i < nCount) {
if (!("")) {
if (("(")) {
nFun++;
isFun = true;
}
else if ((")")) {
nFun--;
}
}
if ( (nFun > 0) || ( (!isFun) && (opt))) {
temp1 += opt;
nTemp++;
opt = (i + nTemp, i + nTemp + 1);
}
else {
if (isFun) {
temp1 += opt;
nTemp++;
}
break;
}
表达式计算源码JAVA实现 来自淘豆网m.daumloan.com转载请标明出处.