about | help | code help+videos | done | prefs |
Write a method that parses a string of "left to right" arithmetic operations. You will be passed in a string such as "50+10/2-4/2". Your goal is to IGNORE the order of operations, and instead just perform the operations in the order they are given. So, to calculate the "left to right" total of "50+10/2-4/2" you would first add 50+10 to get 60. Next 60/2=30. Now subtract 4 from 30 to get 26. The last operation is for you to divide by 2. This is integer division since we want to get an integer answer. 26/2=13. As another example, let's look at "17/2". In this case it is more obvious that we want to do integer division as we want the answer to be the integer 8, not the real number 8.5. We know that we want an integer because this method has 'int' as its return type. For this problem you have a RESTRICTED list of string methods. The ONLY string methods you are allowed to use are: .equals, .substring, .length, and .charAt. Additionally, you are NOT allowed to use any of the numeric object wrapper classes such as the Integer class. You are also NOT allowed to use the StringBuilder class. Look at the test data for additional examples. test2025_04_17_HL_leftToRightMath("1+2+3*5-2/2") → 14 test2025_04_17_HL_leftToRightMath("400+40+4-30-10") → 404 test2025_04_17_HL_leftToRightMath("8000/8-900*2/4") → 50 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 290
Copyright Nick Parlante 2017 - privacy