Skip to content

Instantly share code, notes, and snippets.

@maniish-jaiin
Created July 15, 2020 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maniish-jaiin/c6a38957cda75ec883404daaa7fe03d6 to your computer and use it in GitHub Desktop.
Save maniish-jaiin/c6a38957cda75ec883404daaa7fe03d6 to your computer and use it in GitHub Desktop.
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