I am making an Android app that will eventually be used as a dice roller for a game. I have a keypad that enters an equation into a String. I then parse the String into an array and need to compute the equation. I am using a for loop to go through the array, but I'm not sure how to handle the multiplication when it comes up.
As an example:
String theEquation = "2 + 3 * 6";
String[] result = theEquation.split("\\s+");
So I now have an array that has 2, +, 3, *, 6 in it. How would I go about turning that in to the answer of 20?
I initially used a for loop to just add the entire array together. That works fine when it is just addition. But things get hinky when i add in multiplication.