Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int evalDigit() throws InvalidExpression{
- if (e[i]>='0' && e[i]<='9'){
- int result = e[i]-(int)'0';
- i++;
- return result;
- } else {
- throw new InvalidExpression("index "+i);
- }
- }
- public static int evalTerm() throws InvalidExpression{
- return evalDigit();
- }
- public static int evalExpr() throws InvalidExpression {
- int result=evalTerm();
- while (e[i]=='+' || e[i]=='-'){
- switch (e[i]){
- case '+':
- i++;
- result += evalTerm();
- break;
- case '-':
- i++;
- result -= evalTerm();
- break;
- }
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement