Created
July 15, 2020 11:31
-
-
Save maniish-jaiin/c6a38957cda75ec883404daaa7fe03d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public double evaluate(String s) { | |
String[] elements = getStringArray(s); | |
double result = 0.0; | |
for (int i = 0; i < elements.length; i++) { | |
String c = elements[i]; | |
if (c.equals("+") && i >= 2) { | |
result = parseDouble(elements[i - 1]) + parseDouble(elements[i - 2]); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment