Guest User

Untitled

a guest
Oct 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. //for loop to loop through char of string
  2. for(int i=0; i<expressionString.length(); i++) {
  3.  
  4. //cast char into ascii int
  5. int ascii = (int) charAt(i);
  6.  
  7. //appending to token if one of singly operator symbols: *,/,(,),[,]
  8. if(ascii == 40 || ascii == 41 || ascii == 42 || ascii == 47 || ascii == 91 || ascii == 93){
  9. token.append((char) ascii);
  10. tokenList.add(token.toString());
  11.  
  12. } //append if +, -
  13. else if(ascii == 43 || ascii == 45) {
  14. token.append((char) ascii);
  15.  
  16. //check next char if + or /, if so append to token again
  17. int nextChar = (char) charAt(i+1);
  18. if(nextChar == 43 || nextChar == 45) {
  19. token.append((char) nextChar);
  20. }
  21. tokenList.add(token.toString());
  22.  
  23. } //appending to token if it's a num
  24. else if ( ascii >= 48 || ascii <=57) {
  25. token.append((char) ascii);
  26.  
  27. //check if next char is a num
  28. while ((int) charAt(i+1) >= 48 || (int) charAt(i+1) <= 57) {
  29. //increment i in for loop to check
  30. i++;
  31. token.append((int) charAt(i));
  32. }
  33. tokenList.add(token.toString());
  34. }
  35. //
  36. }
Add Comment
Please, Sign In to add comment