evaluate the value of a expression in java using beanshell by passing variable to Math.pow( ) -


i trying evaluate expression in java directly, though easy expression , seems difficult me using beanshell

anyway , problem:

i can directly evaluate value of exponential using in java

double c = math.pow(2,3); 

or way

int a=2,b=3; double c = math.pow(a,b); 

in beanshell trying same , works:

import bsh.interpreter; interpreter interpreter = new interpreter(); int a1=2, b1=3; string equation = "math.pow(2,3)"; object checkit = interpreter.eval(equation); system.out.println(checkit.tostring); 

but these lines dont work:

string equation = "math.pow(a1,b1)"; object checkit = interpreter.eval(equation); system.out.println(checkit.tostring); 

**this progress**

update : code shows me error message sourced file: inline evaluation of: ``math.pow(finalstr,2);'' : undefined argument:

the beanshell script not have access java local variables. script can see values have been given beanshell interpreter using of set() methods:

import bsh.interpreter; interpreter interpreter = new interpreter(); interpreter.set("a1", 2); interpreter.set("b1", 3); string equation = "math.pow(a1,b1)"; object checkit = interpreter.eval(equation); system.out.println(checkit); 

the javadoc has examples of this.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -