`
speed_guo
  • 浏览: 310678 次
  • 性别: Icon_minigender_1
  • 来自: 湖北
社区版块
存档分类
最新评论

java中的表达式计算--eval函数

阅读更多

     

/**
	 * @param args
	 */
	public static void main(String[] args) {
		//Expression exp = new Expression("0.8*(x-2)/(5-2)+0.2");
		//Expression exp1 = new Expression("Math.pow(0.8,-(x-200)/100)+0.2");
		TestMain0308  t = new TestMain0308();
		String s = "0.8*(1/e pow ((x-200)/100))+0.2";
		System.out.println(s.contains("e"));//判断字符串中是否包含指定的字符
		
		double tvalue = 0.8*Math.pow(Math.E,-(220-200)/100)+0.2;
		//Expression exp1 = new Expression("0.8*(2.71828 pow (-(x-200)/100))+0.2");
		Expression exp1 = new Expression("0.8*(1/e pow ((x-200)/100))+0.2");
		
		
		
		
		Map<String, BigDecimal> variables = new	 HashMap<String, BigDecimal>();
		variables.put("x", new	BigDecimal("200"));
		variables.put("e", new	BigDecimal(Math.E));
		
		BigDecimal result = exp1.eval(variables);    //计算表达式的值
		String str = String.valueOf(result);   //转换成字符串
                     System.out.println(result);
		System.out.println(tvalue);
		System.out.println("result="+str);
		
				
		
				

	}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics