Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. public static int evalDigit() throws InvalidExpression{
  2.  
  3.  
  4. if (e[i]>='0' && e[i]<='9'){
  5. int result = e[i]-(int)'0';
  6. i++;
  7. return result;
  8. } else {
  9. throw new InvalidExpression("index "+i);
  10. }
  11. }
  12.  
  13.  
  14. public static int evalTerm() throws InvalidExpression{
  15.  
  16. return evalDigit();
  17. }
  18.  
  19. public static int evalExpr() throws InvalidExpression {
  20.  
  21. int result=evalTerm();
  22. while (e[i]=='+' || e[i]=='-'){
  23. switch (e[i]){
  24. case '+':
  25. i++;
  26. result += evalTerm();
  27. break;
  28. case '-':
  29. i++;
  30. result -= evalTerm();
  31. break;
  32. }
  33. }
  34. return result;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement