-2

A part of the goal in my app is to receive a mathematical expression (e.g. 1 + 1) by string, and convert it to a BigInteger.
My goal is to have an equivalent to:

BigInteger result = new BigInteger("1+1");
// This will throw an exception of invalid BigInteger

Also, ScriptEngineManager class isn't available for Android.
I still cannot find a way to achieve my goal.
Thanks a lot for helping!

avi12
  • 37
  • 1
  • 8
  • What have you tried so far. Please provide code that you used to achieve what you describe. – MWiesner Dec 19 '15 at 12:27
  • I said, I couldn't find a way to achieve this. – avi12 Dec 19 '15 at 12:31
  • 2
    Your definition of "mathematical expression" is unclear. What is included, what is excluded? You should give a precise definition and describe the problem exactly, otherwise there are many ways to interpret and answer your question... – MWiesner Dec 19 '15 at 12:34
  • 2
    google "expression evaluation" .. [this](http://stackoverflow.com/a/20919547/2521214) is how I do it – Spektre Dec 19 '15 at 12:37

1 Answers1

0

You can try :

//If you have to parse only the result
String result = "2";

BigInteger.valueOf(Long.valueOf("2");

//If you have to parse the whole operation
String result = "1+1";
//create an algo to extract each 1 and determine operation

BigInteger bigIntUn = new BigInteger("1");
BigInteger bigIntAnotherUn = new BigInteger("1");

//you have add (+), min(-), multiply(*) (etc...)
bigIntUn.add(bigIntAnotherUn);
Aurelien
  • 458
  • 1
  • 5
  • 13