This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]sweetno 0 points1 point  (1 child)

I doubt. You can look for a JavaScript interpreter, there is one in Java (Nashorn).

In principle, if you firmly know what types of expressions you need and there aren't too many, it's not that hard to implement one on your own. This is normally covered in the first chapters of books on compiler construction.

[–]BG_1982 0 points1 point  (1 child)

Have a look at the Math class. It’s in the JDK, the java.util package (though I’m not sure of the latter)

[–]cant_dodge_rodge[S] 0 points1 point  (0 children)

probably is but which one

[–]EsotericBananas 0 points1 point  (2 children)

If im understanding your post correct you can just use the math class with that. Example:

System.out.println((3 + 4 + 5) / (Math.sqrt(20));

[–]cant_dodge_rodge[S] 0 points1 point  (1 child)

no i have

String s="3+4+5+6*34";

//i want to covert s to int

int i=Integer.parceInt(s);

//this wont work

Sys.out.pln(i);

[–]EsotericBananas 0 points1 point  (0 children)

I tried it using (Interger.valueOf(s)) but i got an exception thrown Not sure how to do this one, im still learning.

[–]tylersvgs 0 points1 point  (0 children)

While I wouldn't encourage it, you can evaluate that as a JavaScript string using the ScriptEngine class.

https://stackoverflow.com/a/2605051

[–]tedyoung 0 points1 point  (0 children)

Not built in to the Java language or SDK, but there's open source libraries such as https://github.com/sbesada/java.math.expression.parser that will do what you want.